PHP image proportional scaling to generate thumbnail function sharing_PHP tutorial

WBOY
Release: 2016-07-13 10:28:41
Original
958 people have browsed it

Copy code The code is as follows:

/*
*@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;

                                                                                                                                  $resizerreagH =true;                                The smallest aspect ratio between the thumbnail width and height and the original image is the smallest one if($resizereagW && $resizerreagH){
           $radio = $dsimgWratio;
else
                             $radio = $                                                                                                                                  $radio = $dsimgWratio;
                                                                                            resizerreagH){
                                                                                                                                                                                            $imgnewH = $pic_H * $radio;
if(function_exists("imgcopyresampled" )){
//Create the target resource canvas
$dst = imagecreatetruecolor ($imgnewW, $imgnewH);
imagecopyresampled ($dst,$im, 0,0,0,0,$imgnewW,$ imgnewH, $pic_W, $pic_H); imgnewW,$imgnewH,$imgnewH,$pic_W,$pic_H);
      }

        $arr[$filetype]($dst,$thumbname.".$filetype");
                                                                                                                                          The width and height of the original image
//Then the width and height of the thumbnail are the width and height of the original image
filetype");
imagedestroy();
}
}
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/781406.htmlTechArticleCopy the code as follows: ?php /* *@im //Image resources that need to be scaled*@filetype // The thumbnail file type produced*@dstimW //The width of the scaled picture*@dstimH //The height of the scaled picture...
Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template