我需要翻转图像,这样角色才能朝向正确的方向。正如他们所说,这需要“在飞行中”完成。
我的问题是,对于Gif图像,我似乎失去了透明度。(背景变为白色)
下面是代码:(或者有人可以给我一个很好的例子)
$img = imagecreatefromgif("./unit.gif");
$size_x = imagesx($img);
$size_y = imagesy($img);
$temp = imagecreatetruecolor($size_x, $size_y);
imagecolortransparent($img, imagecolorallocate($img, 0, 0, 0));
imagealphablending($img, false);
imagesavealpha($img, true);
$x = imagecopyresampled($temp, $img, 0, 0, ($size_x-1), 0, $size_x, $size_y, 0-$size_x, $size_y);
if ($x) {
$img = $temp;
}
else {
die("Unable to flip image");
}
header("Content-type: image/gif");
imagegif($img);
imagedestroy($img);
发布于 2008-09-15 20:25:24
不是应该这样吗:
imagecolortransparent($img, imagecolorallocate($img, 0, 0, 0));
imagealphablending($img, false);
imagesavealpha($img, true);
...be此命令:
imagecolortransparent($temp, imagecolorallocate($img, 0, 0, 0));
imagealphablending($temp, false);
imagesavealpha($temp, true);
注意:您应该为您创建的$temp映像调用这些函数,而不是源映像。
发布于 2008-09-15 20:45:40
最终结果:
$size_x = imagesx($img);
$size_y = imagesy($img);
$temp = imagecreatetruecolor($size_x, $size_y);
imagecolortransparent($temp, imagecolorallocate($temp, 0, 0, 0));
imagealphablending($temp, false);
imagesavealpha($temp, true);
$x = imagecopyresampled($temp, $img, 0, 0, ($size_x-1), 0, $size_x, $size_y, 0-$size_x, $size_y);
if ($x) {
$img = $temp;
}
else {
die("Unable to flip image");
}
header("Content-type: image/gif");
imagegif($img);
imagedestroy($img);
发布于 2008-09-15 20:23:45
如果你能保证ImageMagick的存在,你可以使用他们的mogrify -flop
命令。它保留了透明度。
https://stackoverflow.com/questions/66518
复制相似问题