简体   繁体   中英

Custom PNG flipping function outputs black background on image

I'm working with the PHP GB library to manipulate images. One of the thing I noticed doesn't come with the GB library is the ability to flip images either vertically or horizontally. 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.

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/

You need to allocate transparency to a specific value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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