Monday, 2 April 2007
Know About PHP Multiple Photo Thumbnail Generator |
| |
|
| |
An article over the Any Example web site, provides PHP function thumbnail generator and trivial image uploading script, which generates series of thumbnails. The author says Built-in PHP library GD does not have ready-to-use function for photo (Jpeg) thumbnail generation. Although there are many such examples on the net, they are usually not suitable for effective generating series of thumbnails (240x240, 140x140, 80x80).
The author gives the following two functions:
thumbnail_generator() function uses proportion-correct scaling: it scales longest side of image to specified value. Following function, thumbnail_calcsize calculates resized width and height (returned as list)thumbnail_generator() function uses two arguments: $srcfile - source JPG file name, and $params array.- $params is a two dimensional array: first dimension (0..n) specifies parameters for each thumbnail, second dimension (string hash) specifies destination file name (key 'file') and thumbnail size (key 'size').
He gives a tip that you should specify largest thumbnail first, as thumbnail_generator will use largest thumbnail result to generate all other. He gives a code to facilitate better understanding. This function is up to 4x faster comparing to subsequent loading and downscaling of the same jpeg file to different resolutions.
The author gives a trivial photo-uploading script, which allows user to upload photo, stores it and generates three thumbnails (240x240, 140x140, 80x80).
He says, the script has three notable code branches:
- Photo uploading form: shown when user simply accesses the page
- Upload processing: executed when POST query is received and file was selected
- Upload result: shown after upload processing, when file GET parameter is added
|
| |
|
|
| |
|
|
| |
|
|
| |
|