generate functionThu, 15 Dec 2022

convert png to jpg, compress 100 and replace file with jpg extension

function convert_file_to_jpg($file) { $image = imagecreatefrompng($file); $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); $quality = 100; // 0 = worst / smaller file, 100 = better / bigger file $file = str_replace('.png', '.jpg', $file); imagejpeg($bg, $file, $quality); imagedestroy($bg); return $file; }

Questions about programming?Chat with your personal AI assistant