PHP字体角度,用给定角度旋转图像 - PHP 7 中文文档

这篇博客介绍了PHP的imagerotate函数,用于按指定角度旋转图像。该函数接受图像资源、旋转角度和背景颜色作为参数,旋转中心位于图像中心,并保持原图像比例。旋转后未覆盖的部分将填充指定的背景颜色。从PHP5.1.0版本开始,增加了一个可选参数ignore_transparent,用于决定是否忽略透明色。示例代码展示了如何将图像旋转180度。请注意,此功能依赖于与GD库捆绑的PHP版本。
摘要由CSDN通过智能技术生成

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

imagerotate – 用给定角度旋转图像

说明

imagerotate

( resource $image

, float $angle

, int $bgd_color

[, int $ignore_transparent = 0

] ) : resource

将 src_im 图像用给定的

angle 角度旋转。bgd_color

指定了旋转后没有覆盖到的部分的颜色。

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

参数

image

由图象创建函数(例如[imagecreatetruecolor()](php7/function.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 度——上下颠倒。

// 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);

?>

以上例程的输出类似于:

ae27f56fbe0e7c630b77dab9e257eabf.png

注释

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值