/**
* desription 压缩图片
* @param sting $imgsrc 图片路径
* @param string $imgdst 压缩后保存路径
*/
private function compressedImage($imgsrc, $imgdst) {
list($width, $height, $type) = getimagesize($imgsrc);
$new_width = $width>800?800:$width;//图片宽度的限制
$new_height =$height>800?ceil($height*800/$width):$height;//自适应匹配图片高度
switch ($type) {
case 1:
$giftype = $this->check_gifcartoon($imgsrc);
if ($giftype) {
header('Content-Type:image/gif');
$image_wp = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromgif($imgsrc);
imagecopyresampled($image_wp, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
//90代表的是质量、压缩图片容量大小
imagejpeg($image_wp, $imgdst, 90);
imagedestroy($image_wp);
PHP图片压缩方法
最新推荐文章于 2024-05-20 20:32:38 发布