自定义PNG翻转功能在图像上输出黑色背景
问题描述:
我正在使用PHP GB库来操作图像。我注意到的事情之一是GB库没有提供垂直或水平翻转图像的功能。所以我开始为它建立我自己的功能。这是我的了:自定义PNG翻转功能在图像上输出黑色背景
function flipImage($image) {
$width = imagesx($image);
$height = imagesy($image);
$out = imagecreatetruecolor($width, $height);
for($i = 0; $i < $width; $i++) {
// Copy the image strip going left to right
imagecopy($out, $image, $width - $i, 0, $i, 0, 1, $height);
}
//$out should now hold our flipped image
return $out;
}
它的工作原理,因为我预料到的,但由于某种原因,返回的图像($out
)有一个黑色的背景,而不是透明的。
有什么办法让返回的图像具有像源图像一样的透明背景吗?