Hello, I have a class of images, and there is a function that converts png images to jpg

case IMAGETYPE_PNG: $image = imagecreatefrompng($tmp); $path = $this->createdir().str_shuffle(substr(md5($tmp), 0, 20)).'.jpg'; imagejpeg($image, $this->cdndir.$path, 100); imagedestroy($image); break; 

but the fact is that with an envelope, if the image has a transparent background, then it is replaced with horrible multi-colored hues, or simply with black, how can you make the replacement of the transparent background with a white color?

    1 answer 1

    You need to create an image with a white background and place a png on top of it:

     $image = imagecreatefrompng($tmp); $bg = imagecreatetruecolor(imagesx($image), imagesy($image)); imagefill($bg, 0, 0, imagecolorallocate($bg, 255, 255, 255)); imagealphablending($bg, TRUE); imagecopy($bg, $image, 0, 0, 0, 0, imagesx($image), imagesy($image)); imagedestroy($image); imagejpeg($bg, $здесьвашpath, 100); imagedestroy($bg); 

    Answer from here