& Lt ;? Php & nbsp;/** & nbsp; * generate image thumbnails & nbsp; * @ param & nbsp; string & nbsp; $ src & nbsp; & nbsp; source image address & nbsp; * @ param & nbsp; string & nbsp; $ savePath thumbnail save address & nbsp;
-
- /**
- * Generating image thumbnails
- *
- * @ Param string $ src source image address
- * @ Param string $ savePath the thumbnail storage address
- * @ Param integer $ width thumbnail width
- * @ Param integer $ height the Thumbnail height
- * @ Return string thumbnail address
- */
- Function buildThumb ($ src, $ savePath, $ width = 220, $ height = 180)
- {
- $ Arr = getimagesize ($ src );
- If (! Is_array ($ arr )){
- Return false;
- }
- // 1, 2, and 3 are gif, jpg, and png, respectively.
- If ($ arr [2]> 4 ){
- Return false;
- }
- $ Func = imagecreatefrom;
- Switch ($ arr [2]) {
- Case 1: $ func. = gif; break;
- Case 2: $ func. = jpeg; break;
- Case 3: $ func. = png; break;
- Default: $ func. = jpeg;
- }
- $ SrcIm = $ func ($ src );
- $ Im = imagecreatetruecolor ($ width, $ height );
- Imagecopyresized ($ im, $ srcIm, 0, 0, 0, 0, $ width, $ height, $ arr [0], $ arr [1]);
- Imagejpeg ($ im, $ savePath );
- Imagedestroy ($ srcIm );
- Imagedestroy ($ im );
- Return true;
- }
- ?>