您的位置:首页 > 编程语言 > PHP开发

php图片等比例压缩

2015-04-23 17:30 302 查看
<?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:
$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,100);
imagedestroy($image_wp);
}

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,100);
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,100);
imagedestroy($image_wp);
break;
}
}
image_png_size_add('active1.jpg','active2.jpg',110,110);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: