A function used to create image thumbnails.
/**
- * Create an image thumbnail and return the true result.
- *
- * @ Param string $ cat Directory
- * @ Param string $ oldname original image file name
- * @ Param string $ newname New graph file name
- * @ Param int $ width: thumbnail width
- * @ Param int $ height the Thumbnail height
- * @ Return
- */
- Function thumb ($ cat, $ oldname, $ newname, $ width = 160, $ height = 120 ){
- $ SrcFile = $ cat. "/". $ oldname;
- $ Data = getimagesize ($ srcFile );
- $ DscFile = $ cat. "/". $ newname;
Switch ($ data [2]) {
- Case 1:
- $ Im = imagecreatefromgif ($ srcFile );
- Break;
Case 2:
- $ Im = imagecreatefromjpeg ($ srcFile );
- Break;
Case 3:
- $ Im = imagecreatefrompng ($ srcFile );
- Break;
- }
$ SrcW = imagesx ($ im );
- $ SrcH = imagesy ($ im );
If ($ srcW/$ width) >=( $ srcH/$ height )){
- $ Temp_height = $ height;
- $ Temp_width = $ srcW/($ srcH/$ height );
- $ Src_X = abs ($ width-$ temp_width)/2 );
- $ Src_Y = 0;
- }
- Else {
- $ Temp_width = $ width;
- $ Temp_height = $ srcH/($ srcW/$ width );
- $ Src_X = 0;
- $ Src_Y = abs ($ height-$ temp_height)/2 );
- }
$ Temp_img = imagecreatetruecolor ($ temp_width, $ temp_height );
- Imagecopyresized ($ temp_img, $ im, 0, 0, 0, $ temp_width, $ temp_height, $ srcW, $ srcH );
$ Ni = imagecreatetruecolor ($ width, $ height );
- Imagecopyresized ($ ni, $ temp_img, 0, 0, $ src_X, $ src_Y, $ width, $ height, $ width, $ height );
- $ Cr = imagejpeg ($ ni, $ dscFile );
If ($ cr ){
- Chmod ($ dscFile, 0777 );
- Return true;
- }
- }
- ?>
|