I have a PNG image with transparent background, I want to create Progressive JPEG with a white background, any workaround is really appreciated and is that right to create PJPEG from PNG?
below is my workaround, I just want to know is this really right approach to proceed.
$filePath = 'a.png';
$savePath = 'a.jpeg';
$colorRgb = array('red' => 255, 'green' => 255, 'blue' => 255);
$img = @imagecreatefrompng($filePath);
$width = imagesx($img);
$height = imagesy($img);
$backgroundImg = @imagecreatetruecolor($width, $height);
$color = imagecolorallocate($backgroundImg, $colorRgb['red'], $colorRgb['green'], $colorRgb['blue']);
imagefill($backgroundImg, 0, 0, $color);
imagecopy($backgroundImg, $img, 0, 0, 0, 0, $width, $height);
imageinterlace($backgroundImg, 1);
imagejpeg($backgroundImg, $savePath, 80);