网站首页  汉语字词  英语词汇  考试资料  写作素材  旧版资料

请输入您要查询的范文:

 

标题 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();
    }
    }
    ?>
随便看

 

在线学习网范文大全提供好词好句、学习总结、工作总结、演讲稿等写作素材及范文模板,是学习及工作的有利工具。

 

Copyright © 2002-2024 cuapp.net All Rights Reserved
更新时间:2025/5/23 13:21:51