imagerotate
以给定角度旋转图像
PHP 4及以上版本
imagerotate函数用于旋转一幅图像。可以将图像旋转指定的角度,旋转的背景色默认为白色。
imagerotate(resource $image, float $angle, int $bgd_color): resource
返回旋转后的图像资源。如果失败,则返回false。
下面是一个使用imagerotate函数的示例代码。
在这个示例中,我们首先加载一张图片文件,然后使用imagerotate函数将其旋转45度,并将空白部分的背景色设置为黑色。最后,我们通过imagepng将图像输出到浏览器。
<?php // 加载图片 $image = imagecreatefromjpeg('example.jpg'); <p>// 旋转图片45度,背景色为黑色<br> $rotated_image = imagerotate($image, 45, imagecolorallocate($image, 0, 0, 0));</p> <p>// 输出旋转后的图片<br> header('Content-Type: image/png');<br> imagepng($rotated_image);</p> <p>// 释放内存<br> imagedestroy($image);<br> imagedestroy($rotated_image);<br> ?><br>