In the php tutorial, upload image thumbnails are generated by proportional scaling of the specified size.
/**
**
* Proportional Scaling
* @ Param unknown_type $ srcImage source image path
* @ Param unknown_type $ toFile target image path
* @ Param unknown_type $ maxWidth maximum width
* @ Param unknown_type $ maxHeight maximum height
* @ Param unknown_type $ imgQuality Image Quality
* @ Return unknown
*/
Function resize ($ srcImage, $ toFile, $ maxWidth = 100, $ maxHeight = 100, $ imgQuality = 100)
{
List ($ width, $ height, $ type, $ attr) = getimagesize ($ srcImage );
If ($ width <$ maxWidth | $ height <$ maxHeight) return;
Switch ($ type ){
Case 1: $ img = imagecreatefromgif ($ srcImage); break;
Case 2: $ img = imagecreatefromjpeg ($ srcImage); break;
Case 3: $ img = imagecreatefrompng ($ srcImage); break;
}
$ Scale = min ($ maxWidth/$ width, $ maxHeight/$ height); // calculates the bloom ratio.
If ($ scale <1 ){
$ NewWidth = floor ($ scale * $ width );
$ NewHeight = floor ($ scale * $ height );
$ NewImg = imagecreatetruecolor ($ newWidth, $ newHeight );
Imagecopyresampled ($ newImg, $ img, 0, 0, 0, 0, $ newWidth, $ newHeight, $ width, $ height );
$ NewName = "";
$ ToFile = preg_replace ("/(.gif |. jpg |. jpeg |. png)/I", "", $ toFile );
Switch ($ type ){
Case 1: if (imagegif ($ newImg, "Too tofile=newname.gif", $ imgQuality ))
Return "invalid newname.gif"; break;
Case 2: if (imagejpeg ($ newImg, "$tofile=newname.jpg", $ imgQuality ))
Return "maid"; break;
Case 3: if (imagepng ($ newImg, "$tofile=newname.png", $ imgQuality ))
Return "maid"; break;
Default: if (imagejpeg ($ newImg, "$tofile=newname.jpg", $ imgQuality ))
Return "maid"; break;
}
Imagedestroy ($ newImg );
}
Imagedestroy ($ img );
Return false;
}