我有1 MB高清分辨率图像。我希望文件大小将减少到50%min(512KB)。我已经尝试使用PHP,但它不适合我。如果有人知道请帮助我。
赞https://tinyjpg.com/这个网站。
$filename = "image.jpg"; // 1 mb image file
header('Content-Type: image/jpeg');
list($width_orig, $height_orig) = getimagesize($filename);
$width = $width_orig;
$height = $height_orig;
$ratio_orig = $width_orig / $height_orig;
if ($width / $height > $ratio_orig) {
$width = $height * $ratio_orig;
} else {
$height = $width / $ratio_orig;
}
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
imagejpeg($image_p, "image_resized.jpg", 100);
答案 0 :(得分:0)
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);
imagejpeg($image, $destination_url, $quality);
return $destination_url;
}
答案 1 :(得分:-1)