导航首页 » 技术教程 » PHP:imagerotate()的用法_GD库图像处理函数
PHP:imagerotate()的用法_GD库图像处理函数 167 2023-12-15   

imagerotate

(PHP 4 >= 4.3.0, PHP 5)

imagerotate — 用给定角度旋转图像

说明

resource imagerotate ( resource $image , float $angle , int $bgd_color [, int $ignore_transparent = 0 ] )

src_im 图像用给定的 angle 角度旋转。bgd_color 指定了旋转后没有覆盖到的部分的颜色。

旋转的中心是图像的中心,旋转后的图像会按比例缩小以适合目标图像的大小——边缘不会被剪去。

参数

image

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

angle

Rotation angle, in degrees. The rotation angle is interpreted as the number of degrees to rotate the image anticlockwise.

bgd_color

Specifies the color of the uncovered zone after the rotation

ignore_transparent

如果被设为非零值,则透明色会被忽略(否则会被保留)。

返回值

返回旋转后的图像资源, 或者在失败时返回 FALSE

更新日志

版本 说明 5.1.0 新增: ignore_transparent

范例

Example #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);
?>

以上例程的输出类似于:

注释

Note: 此函数仅在与 GD 库捆绑编译的 PHP 版本中可用。


!!!站长长期在线接!!!

网站、小程序:定制开发/二次开发/仿制开发等

各种疑难杂症解决/定制接口/定制采集等

站长微信:lxwl520520

站长QQ:1737366103