[英]Custom PNG flipping function outputs black background on image
I'm working with the PHP GB library to manipulate images. 我正在使用PHP GB库来处理图像。 One of the thing I noticed doesn't come with the GB library is the ability to flip images either vertically or horizontally.
我注意到GB库没有提供的功能之一是能够垂直或水平翻转图像。 So I went about building my own function for it.
因此,我开始为此构建自己的功能。 This is what I got:
这就是我得到的:
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;
}
It works as I expected it to, but for some reason the returned image ( $out
) has a black background instead of a transparent one. 它按照我的预期工作,但是由于某种原因,返回的图像(
$out
)具有黑色背景,而不是透明背景。
Is there any way to get the returned image to have a transparent background like the source image was? 有什么办法可以使返回的图像具有与源图像一样的透明背景?
http://www.akemapa.com/2008/07/10/php-gd-resize-transparent-image-png-gif/ http://www.akemapa.com/2008/07/10/php-gd-resize-transparent-image-png-gif/
You need to allocate transparency to a specific value. 您需要将透明度分配给特定值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.