Copy CodeThe code is as follows:
/*
* @im//Picture resources that need to be scaled
* @filetype//production of thumbnail file type
* @dstimW//Zoom the width of the picture
* @dstimH//height of the picture to zoom
* @thumbname//thumbnail file name
function Makethumb ($im, $dstimW, $dstimH, $thumbname, $filetype) {
Get the width and height of 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;
}
//thumbnail width height and original aspect ratio, whichever is the smallest
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")) {
//Create target resource canvas
$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{//the width and height of the thumbnail itself is greater than the width and height of the original image
The width and height of the thumbnail is the height of the original image and the original
$arr [$filetype] ($im, $thumbname. ". $filetype ");
Imagedestroy ();
}
}
?>
http://www.bkjia.com/PHPjc/781406.html www.bkjia.com true http://www.bkjia.com/PHPjc/781406.html techarticle Copy the code as follows:? PHP/* * @im//Image resource that needs to be scaled * @filetype//thumbnail file type created * @dstimW//Zoom picture Width * @dstimH//Zoom picture of the high ...