相關關鍵詞
關于我們
最新文章
淺談關于PHP解決圖片無損壓縮的問題
本文介紹了關于PHP解決圖片無損壓縮的問題,分享給大家,具體如下:
代碼如下:
header("Content-type: image/jpeg"); $file = "111.jpg"; $percent = 1.5; //圖片壓縮比 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); //輸出壓縮后的圖片 imagedestroy($dst_im); imagedestroy($src_im);