[英]Php Gd rotate image
你好,
我试图绕中心旋转圆形图像,然后切掉侧面。 我看到了imagerotate函数,但是它似乎没有绕中心旋转。
有人有什么建议吗?
谢谢。
更新:因为它是一个圆,所以我想剪掉边缘,使圆保持相同的尺寸。
我用以下代码成功解决了这个问题
$width_before = imagesx($img1);
$height_before = imagesy($img1);
$img1 = imagerotate($img1, $angle, $mycolor);
//but imagerotate scales, so we clip to the original size
$img2 = @imagecreatetruecolor($width_before, $height_before);
$new_width = imagesx($img1); // whese dimensions are
$new_height = imagesy($img1);// the scaled ones (by imagerotate)
imagecopyresampled(
$img2, $img1,
0, 0,
($new_width-$width_before)/2,
($new_height-$height_before)/2,
$width_before,
$height_before,
$width_before,
$height_before
);
$img1 = $img2;
// now img1 is center rotated and maintains original size
希望能帮助到你。
再见
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.