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.
Each time you need to display a thumbnail, you call the image.php script like this:
[xhtml]<a href=”images/image.jpg”><img src=”image.php/image.jpg?width=75&height=75&cropratio=1:1&quality=100&image=http://www.domain.com/images/image.jpg” alt=”” /></a>[/xhtml]
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.
Once a week or so we send an email with our best content. We never bug you, we just send you our latest piece of content.
If you found any value in this post, agree, disagree, or have anything to add - please do. I use comments as my #1 signal for what to write about. Read our comment policy before commenting! Comments such as "Thank you!", "Awesome!", "You're the man!" are either marked as spam or stripped from URL.