PHP Smart Image Resizing – Thumbnails On The Fly

December 3rd, 2009 | Author: Chip

cursor-resize

Ever since I discovered PHP I tried to simplify everything by splitting files into most used parts and using include() to add them, reading files from directories and generating galleries on the fly, or by using many tricks to make my developer life easier.

Today, I’ll show you how to use PHP and GD library to show perfectly cropped thumbnails for your large images. This script even creates a cache folder, so the next time a user visits your site, the images will be retrieved automatically.

I’m using a script called Smart Image Resizer, the current version being 1.4.1. You can download it from the author’s page, or from here.

Each time you need to display a thumbnail, you call the image.php script like this:

<a href="images/image.jpg"><img src="image.php/image.jpg?width=75&amp;height=75&amp;cropratio=1:1&amp;quality=100&amp;image=http://www.domain.com/images/image.jpg" alt="" /></a>

You need to use a full path for the image parameter. The other parameters are self-explanatory. My example will show a square thumbnail, 75px*75px, and a quality of 100 out of 100. The cropratio parameter tells the script to generate a square thumbnail by cropping the wider sides.

That’s it! Good luck.

3 comments

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

CommentLuv Enabled
Get Adobe Flash playerPlugin by wpburn.com wordpress themes