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);
                }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/1b0a09aea6148ed84e0e2d3cee7e87b3.html