A McGraw Hill Book Plug-in PHP: 100 Power Solutions
By Robin Nixon (McGraw Hill 2010, ISBN 978-0071666596)

Home | About | Buy It | Download | Contact

Select Chapter: 1  2  3  4  5  6  7  8  9 10 11 12

Chapter 4: Plug-in 13 - Make Thumbnail

There are many thumbnail programs about that will take a large image and reduce it down to a thumbnail for you, often supporting working in batches. But what about turning user uploaded images into thumbnails? Obviously you don't want to simply send a large image to the browser and have HTML resize it as the quality wouldn't be great, and your bandwidth would go through the roof. So you need something to handle this process on the fly, which is where this plug-in comes in handy. With it you specify a source image and the maximum dimensions allowed for the new thumbnail. The function will then resize the image, retaining the aspect ratio, so that whichever of the height or width is the larger dimension is then set to the new maximum size, and the other is reduce in proportion.

The Figure shows the smiley face image, from the previous plug-in, used as a thumbnail source for two smaller thumbnail images.