imagerotate

(PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8)

imagerotate用给定角度旋转图像

说明

imagerotate(
    GdImage $image,
    float $angle,
    int $background_color,
    bool $ignore_transparent = false
): GdImage|false

image 图像按指定 angle 角度旋转。

旋转的中心是图像的中心,旋转后的图像可能与原始图像具有不同的尺寸。

参数

image

由图象创建函数(例如imagecreatetruecolor())返回的 GdImage 对象。

angle

旋转角度,以度为单位。旋转角度是为逆时针旋转图像的度数。

background_color

指定旋转后未覆盖区域的颜色

ignore_transparent

参数未使用。

返回值

返回旋转图像后的图像对象, 或者在失败时返回 false

更新日志

版本 说明
8.0.0 成功时此函数现在返回 GDImage 实例;之前返回 resource
8.0.0 image 现在需要 GdImage 实例;之前需要有效的 gd resource
8.0.0 未使用的 ignore_transparent 现在接受 bool;之前接受 int

范例

示例 #1 图像旋转 180 度

示例把图像旋转 180 度——上下颠倒。

<?php
// File and rotation
$filename = 'test.jpg';
$degrees = 180;

// Content type
header('Content-type: image/jpeg');

// Load
$source = imagecreatefromjpeg($filename);

// Rotate
$rotate = imagerotate($source, $degrees, 0);

// Output
imagejpeg($rotate);

// Free the memory
imagedestroy($source);
imagedestroy($rotate);
?>

以上例程的输出类似于:

示例输出:图像旋转 180 度

注释

注意:

此函数受到 imagesetinterpolation() 中设定的插值方法影响。

参见

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top