生成缩略图

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

生成缩略图

  2021-03-16 我要评论
想了解生成缩略图的相关内容吗,在本文为您仔细讲解的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:|生成|成缩|缩略|略图|图|,下面大家一起来学习吧。

生成缩略图 $tx=GetImageSize($sample);
  if($tx[0]<=$tx[1] and $tx[1]>=120){
     $height=120;
     $width=intval($height*$tx[0]/$tx[1]);
  }
  if($tx[0]>=$tx[1] and $tx[0]>=100){
     $width=100;
     $height=intval($width*$tx[1]/$tx[0]);
  }
  if($tx[0]<100 and $tx[1]<120){
     $width=$tx[0];
     $height=$tx[1];
  }

  makethumb2($sample,$target,$width,$height);

  // $srcFile: 源文件
  // $dstFile: 目标文件
  // $dstW: 目标图片宽度
  // $dstH: 目标文件高度
  function makethumb2($srcFile,$dstFile,$dstW,$dstH){
           $data=GetImageSize($srcFile,&$info);
           switch($data[2]){
                  case 1:
                       $im=@ImageCreateFromGIF($srcFile);
                       break;
                  case 2:
                       $im=@ImageCreateFromJPEG($srcFile);
                       break;
                  case 3:
                       $im=@ImageCreateFromPNG($srcFile);
                       break;
           }
           $srcW=ImageSX($im);
           $srcH=ImageSY($im);
           $ni=ImageCreate($dstW,$dstH);
           ImageCopyResized($ni,$im,0,0,0,0,$dstW,$dstH,$srcW,$srcH);
           ImageJpeg($ni,$dstFile);
           // 如果需要输出到浏览器,那么将上一句改为ImageJpeg($ni);
           // 如果需要其它格式的图片,改动最后一句就可以了
  }

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们