繁体   English   中英

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

[英]Custom PNG flipping function outputs black background on image

我正在使用PHP GB库来处理图像。 我注意到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;
}

它按照我的预期工作,但是由于某种原因,返回的图像( $out )具有黑色背景,而不是透明背景。

有什么办法可以使返回的图像具有与源图像一样的透明背景?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM