你好,Php Gd旋转图像
我想旋转中心周围的圆形图像,然后切断双方。我看到imagerotate函数,但它似乎不围绕中心旋转。
任何人有任何建议吗?
谢谢。
更新:由于它是一个圆形,我想切割边缘并保持我的圆圈的尺寸相同。
你好,Php Gd旋转图像
我想旋转中心周围的圆形图像,然后切断双方。我看到imagerotate函数,但它似乎不围绕中心旋转。
任何人有任何建议吗?
谢谢。
更新:由于它是一个圆形,我想切割边缘并保持我的圆圈的尺寸相同。
documentation说它确实围绕中心旋转。
不幸的是,它也表示它会缩放图像,使其仍然适合。这意味着无论你做这个功能会改变你的内部圆形图像的大小。
你可以(相对容易)计算出多少的缩减会发生,然后预分频将图像上适当提前。
如果你有PHP“ImageMagick的”功能available你可以用这些代替 - 他们显然不缩放图像。
先调整大小然后*然后*旋转应该产生更好的质量图像。 – soulmerge 2009-04-23 10:10:26
我成功地面对这个问题用下面的代码
$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
希望它能帮助。
再见
正如一个随机的阿里纳斯,PHP推出了一个更新刚刚能解决与GD imagerotate一个安全漏洞...只是认为这是一个有趣的珍闻。 – KyleFarris 2009-04-23 13:41:33