Copy codeThe Code is as follows:
<? Php
/*
* @ Im // The image resource to be scaled
* @ Filetype // The type of the created thumbnail File
* @ DstimW // resize the Image Width
* @ DstimH // resize the Image Height
* @ Thumbname // name of the thumbnail File
Function makethumb ($ im, $ dstimW, $ dstimH, $ thumbname, $ filetype ){
// Obtain the width and height of the 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;
}
// The width and height of the thumbnail, and the aspect ratio of the source image, 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 the target resource canvas
$ Dst = imagecreatetruecolor ($ imgnewW, $ imgnewH );
Imagecopyresampled ($ dst, $ im, 0, 0, 0, $ imgnewW, $ imgnewH, $ pic_W, $ pic_H );
} Else {
$ Dst = imagecreate ($ imgnewW, $ imgnewH );
Imagecopyresized ($ dst, $ im, 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 are greater than the width and height of the source image.
// The thumbnail width and thumbnail height are the width and height of the source image.
$ Arr [$ filetype] ($ im, $ thumbname. ". $ filetype ");
Imagedestroy ();
}
}
?>