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
switch($image_extension){
case 'gif':
case 'GIF':
$image_orig_resource = imagecreatefromgif($image_orig_path);
break;
case 'png':
case 'PNG':
$image_orig_resource = imagecreatefrompng($image_orig_path);
break;
case 'jpg':
case 'jpeg':
case 'JPG':
case 'JPEG':
$image_orig_resource = imagecreatefromjpeg($image_orig_path);
break;
default:
throw new Exception('Extension not supported');
}
$image_resource = imagecreatetruecolor($width, $height);
imagefill($image_resource, 0, 0, imagecolorallocate($image_resource, 255, 255, 255)); // white background;
imagecopyresampled($image_resource, $image_orig_resource, 0, 0, 0, 0, $width, $height, $image_orig_width, $image_orig_height);
imagejpeg($image_resource, $image_path, 100); // quality: [0-100]