<?php
/**
* desription 压缩图片
* @param sting $imgsrc 图片路径
* @param string $imgdst 压缩后保存路径
*/
function image_png_size_add($imgsrc,$imgdst,$dst_w,$dst_h){
list($width,$height,$type)=getimagesize($imgsrc);
$new_width = $dst_w;
$new_height =$dst_h;
switch($type){
case 1:
$image_wp=imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromgif($imgsrc);
imagecopyresampled($image_wp, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagejpeg($image_wp, $imgdst,100);
imagedestroy($image_wp);
break;
case 2:
$image_wp=imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($imgsrc);
imagecopyresampled($image_wp, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagejpeg($image_wp, $imgdst,100);
imagedestroy($image_wp);
break;
case 3:
$image_wp=imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefrompng($imgsrc);
imagecopyresampled($image_wp, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagejpeg($image_wp, $imgdst,100);
imagedestroy($image_wp);
break;
}
}
image_png_size_add('active1.jpg','active2.jpg',110,200);
php图片等比例压缩
最新推荐文章于 2023-03-13 23:00:22 发布