标题 | php图片等比例缩放生成缩略图函数分享 |
内容 | 代码如下: <?php /* *@im //需要缩放的图片资源 *@filetype //制作的缩略图文件类型 *@dstimw //缩放的图片的宽度 *@dstimh //缩放的图片的高度 *@thumbname //缩略图文件名字 function makethumb($im,$dstimw,$dstimh,$thumbname ,$filetype){ //获取im的宽度和高度 $pic_w=imagesx($im); $pic_h=imagesy($im); $arr = array(); swith($filetype){ case 'jpg': $arr[$filetype]=imagejpeg; break; case 'png'; $arr[$filetype]=imagepng; break; case 'jif'; $arr[$filetype]=imagegif; } if(($dstimgw && $dstimgw<$pic_w) || ($dstimgh && $dstimgh<$pic_h) ){ if($dstimgw && $dstimgw<$pic_w){ $dsimgwratio = $dstimgw / $pic_w; $resizereagw =true; } if($dstimgh && $ $dstimgh <$pic_h){ $dsimghratio = $dstimgh/$pic_h; $resizerreagh =true; } //缩略图宽高和原图宽高比,取最小的那个 if($resizereagw && $resizerreagh){ if($dsimgwratio<$dsimghratio) $radio = $dsimgwratio; else $radio = $dsimghratio; } if($resizereagw && !$resizerreagh ){ $radio = $dsimgwratio; } if(!$resizereagw && $resizerreagh){ $radio = $dsimghratio ; } $imgneww = $pic_w * $radio; $imgnewh = $pic_h * $radio; if(function_exists(imgcopyresampled)){ //创建目标资源画布 $dst = imagecreatetruecolor ($imgneww, $imgnewh); imagecopyresampled ($dst,$im,0,0,0,0,$imgneww,$imgnewh,$pic_w,$pic_h); }else{ $dst=imagecreate($imgneww, $imgnewh); imagecopyresized ($dst, $im,0,0,0,0,$imgneww,$imgnewh,$imgnewh,$pic_w,$pic_h); } $arr[$filetype]($dst,$thumbname..$filetype); imagedestroy ($dst); }else{//缩略图自身的宽和高已经大于了原图的宽和高 //则缩略图的宽和缩略的高就是原图的宽和原图的高 $arr[$filetype]($im,$thumbname..$filetype); imagedestroy(); } } ?> |
随便看 |
|
在线学习网考试资料包含高考、自考、专升本考试、人事考试、公务员考试、大学生村官考试、特岗教师招聘考试、事业单位招聘考试、企业人才招聘、银行招聘、教师招聘、农村信用社招聘、各类资格证书考试等各类考试资料。