How to replace black background with white when resizing/converting PNG images with transparent backgrounds to JPEG.

后端 未结 5 2128
执念已碎
执念已碎 2020-12-14 17:45

I am using a script that lets users upload images. The script resizes and converts the images to JPEG.

The problem I have is when a PNG with transparency is uploaded

5条回答
  •  独厮守ぢ
    2020-12-14 18:19

    After Image true colour add the lines:

        $file = imagecreatetruecolor($width, $height);
        $background = imagecolorallocate($file, 0, 0, 0);
        imagecolortransparent($file, $background);
        imagealphablending($file, false);
        imagesavealpha($file, true);
    

    This will help in mailtaining alpha for all formats. Ping if u dont get answer.

提交回复
热议问题