minpic方法里传参数图片路径用逗号隔开的逗号字符串
//返回压缩图片路径数组
function minpic($maxpicdata){
$picdata = explode(',', $maxpicdata);
array_pop($picdata); //因为传进来的最后还有一个逗号,所以需要去掉最后一个空数组,看实际情况操作
foreach($picdata as $p){
$onepic = substr($p,1);
$type = explode('.',$onepic);
$minpic = $type['0'].'min'.'.'.$type['1']; //重新生成的小图的文件名
$minpicdata .= '/'.$minpic.','; //要返回的逗号字符串路径
image_png_size_add($onepic,$minpic); //循环使用压缩的方法
}
return $minpicdata;
}
压缩图片方法 参数 图片路径 压缩后的图片文件名
//压缩图片
function image_png_size_add($imgsrc,$imgdst){
list($width,$height,$type)=getimagesize($imgsrc); //获取图片信息
$new_width = ($width<600?600:$width)*0.3; //设置压缩的大小
$new_height =($height<600?600:$height)*0.3;
switch($type){
case 1:
$giftype=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);
imagejpeg($image_wp, $imgdst,75);
imagedestroy($image_wp);
}
break;
case 2:
header('Content-Type:image/jpeg');
$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,75);
imagedestroy($image_wp);
break;
case 3:
header('Content-Type:image/png');
$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,75);
imagedestroy($image_wp);
break;
}
}
网友评论