以下对 png 文件非常有效,但对于 jpeg/jpg 压缩不起作用。
function compressImage($source, $destination, $quality) {
$info = getimagesize($source);
if ($info['mime'] == 'image/jpeg') $image = imagecreatefromjpeg($source);
elseif ($info['mime'] == 'image/png') $image = imagecreatefrompng($source);
imagejpeg($image, $destination, $quality);
return $destination;
}
我如何让它压缩jpeg?