旋转PNG图像,并保持透明背景

时间:2011-05-09 16:58:41

标签: php image png rotation transparent

我想旋转图像,但我似乎无法维护图像本身。

这就是我所拥有的:

// Content type
header('Content-type: image/png');  

$image = 'http://mapning.com/img/plane.png';
$file = imagecreatefrompng($image);
// Rotate
$rotate = imagerotate($file, $angle, 0);
// Output
imagepng($rotate);

我做错了什么?

2 个答案:

答案 0 :(得分:4)

您必须专门强制GD保持透明度。尝试

imagesavealpha($file, TRUE);
imagepng()来电之前

答案 1 :(得分:1)

对我来说有什么帮助,无论是GD还是ImageMagick,用于获取最终要覆盖的背景颜色的十六进制/ rgb代码。然后,将其用作“背景”颜色。旋转后,将该颜色转换为透明。然后,一旦进行覆盖,小的抗锯齿边缘看起来会很平滑。

相关问题