PHP image and other proportional scaling to generate a thumbnail function for sharing. Copy the code as follows :? Php ** @ im the image resource to be scaled * @ filetype the thumbnail file type created * @ dstimW the width of the scaled image * @ dstimH the height of the scaled image
The code is as follows:
/*
* @ 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 ();
}
}
?>
The http://www.bkjia.com/PHPjc/781406.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/781406.htmlTechArticle code is as follows :? Php/** @ im // The Image resource to be scaled * @ filetype // The thumbnail file type * @ dstimW // the width of the scaled image * @ dstimH // the image height...