Php 自定义PNG翻转功能在图像上输出黑色背景

Php 自定义PNG翻转功能在图像上输出黑色背景,php,image-manipulation,gd,flip,Php,Image Manipulation,Gd,Flip,我正在使用PHPGB库来处理图像。我注意到GB库没有提供的一个功能是垂直或水平翻转图像。所以我开始为它构建自己的函数。这就是我得到的: function flipImage($image) { $width = imagesx($image); $height = imagesy($image); $out = imagecreatetruecolor($width, $height); for($i = 0; $i < $width; $i++) {

我正在使用PHPGB库来处理图像。我注意到GB库没有提供的一个功能是垂直或水平翻转图像。所以我开始为它构建自己的函数。这就是我得到的:

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;
}
函数flipImage($image){
$width=imagesx($image);
$height=imagesy($image);
$out=ImageCreateTureColor($width,$height);
对于($i=0;$i<$width;$i++){
//从左向右复制图像条
imagecopy($out,$image,$width-$i,0,$i,0,1,$height);
}
//$out现在可以保存翻转的图像
退回$out;
}
它的工作原理与我预期的一样,但由于某种原因,返回的图像(
$out
)的背景是黑色的,而不是透明的

有没有办法使返回的图像具有与源图像相同的透明背景?

您需要将透明度分配给特定的值