我试图降低大型JPEG图片的质量(使用PHP)并且愿意放弃一些质量。使用此代码
function compress_image($source_url, $destination_url, $quality) {
$info = getimagesize($source_url);
if ($info['mime'] == 'image/jpeg') $image = imagecreatefromjpeg($source_url);
elseif ($info['mime'] == 'image/gif') $image = imagecreatefromgif($source_url);
elseif ($info['mime'] == 'image/png') $image = imagecreatefrompng($source_url);
//save it
imagejpeg($image, $destination_url, $quality);
//return destination file url
return $destination_url;
}
$source_photo = $file;
$dest_photo = $newfile;
$d = compress_image($source_photo, $dest_photo, 70);
但文件(输出)的大小实际上比原始大 (677kb vs 639kb)但我注意到保存在我的电脑上的DPI被提升到96 DPI?怎么能阻止这个?任何想法..我希望文件大小更小