0

Trying to take a .gif and make it a .jpg with white background using imagejpeg().

If I do this from a .jpg file all is well and good with a white background, but using from a .gif creates black background ...

$src = imagecreatefromgif($original_file);
$tmp = imagecreatetruecolor($new_width, $new_height);
imagealphablending($tmp, false);
imagesavealpha($tmp, true);
$transparent = imagecolorallocatealpha($tmp, 255, 255, 255, 127);
imagefilledrectangle($tmp, 0, 0, $new_width, $new_height, $transparent);
imagecopyresampled($tmp, $src, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagejpeg($tmp, $new_file, 80);

TROUBLESOME GIF

enter image description here

CODE IN THE DUPLICATE WORKS

The duplicate in question is about converting PNGs to JPG. But there is code that that works for converting GIFs to JPG.

ma77c
  • 1,052
  • 14
  • 31

0 Answers0