如何用php 壓縮圖片 廢話不說 直接上代碼
header("Content-type: image/jpeg");
//獲取圖片路徑
$file = "123.jpg";
$percent = 0.3; //圖片壓縮比
list($width, $height) = getimagesize($file); //獲取原圖尺寸
//縮放尺寸
$newwidth = $width * $percent;
$newheight = $height * $percent;
$src_im = imagecreatefromjpeg($file);
$dst_im = imagecreatetruecolor($newwidth, $newheight);
imagecopyresized($dst_im, $src_im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagejpeg($dst_im,$file); //輸出壓縮后的圖片
imagedestroy($dst_im);
imagedestroy($src_im);