Cool Image Thumbnail Class
p. Back in May, GenXDesign, released their “PHP Thumbnail Class”:http://www.gen-x-design.com/projects/php-thumbnailer-class/. Ok, so it’s not exactly “hot” news, it’s still an interesting piece of code.
p. I’ve seen a lot of implementations of thumb nail functionality in PHP, I’ve even written a couple of my own. I like this class thought. In looking over the code the first thing you notice is that it’s clean code. I don’t mean they use the latest whiz-bang method to cshave a few keystrokes. This code is simple, nicely formatted and easy to read through. My only real problem with the code itself is that it is not terribly well documented. That can be forgiven since easy to read.
p. !>http://www.gen-x-design.com/images_demos/thumb_step2.jpg! The class itself has everything you need to create thumbnails.
* Works with gif,jpg, and png images
* Ability to resize by percentage, width, or height
* Ability to set quality of jpg images (0-100%)
* Ability to create a square crop of the image from any point
* Ability to perform multiple manipulations and saves without re-initializing class, or reloading original image
* Ability to display manipulated image on the fly, enabling dynamic image generation in your scripts
p. They even have a “demo page”:http://www.gen-x-design.com/demo_thumbnail.php with several samples, including the cute little fellow on the right.
p. The class is available in 2 flavors, PHP 4 and PHP 5. It is licensed under the MIT license.
p. =C=


4 comments to “Cool Image Thumbnail Class”
August 29th, 2006 at 2:15 pm
I was just about to start hunting for a nice little class like this. Cheers!
August 30th, 2006 at 1:39 pm
Ah fine, I was just looking for such a class.
I just tried PEARs Image_Transform, but it annoyed me with its inability to perform multiple transforms and so i was lucky to see the "Ability to perform multiple manipulations" feature in your listing, although i like the Image_Transform API better, but who cares
September 1st, 2006 at 3:26 am
No, I don’t agree to the coolness of this class. Functionality might be cool, but the API isn’t.
Why you have to first set a percent value of an attribute, before calling a method to resize the picture?
$thumb->percent = 50;
$thumb->resize();
Why not simply
$thumb->resize(50);
If you want to do another operation you first have to reset some attributes
$thumb->percent = 0; // <– the reset
$thumb->maxWidth = 125;
$thumb->resize();
Why not
$thumb->resize(null, 125);
assuming the signature of this method is
function resize($percent, $maxWidth = null, $maxHeight = null)
(or how about having two methods – resizePercent($percent) and resize($width, $height) – or something like this)
And so one. The whole class is built this not very OOP-like way. OOP should hide implementation details.
Almost all methods of this class doesn’t use parameters. Instead you have to set attributes first.
It’s like setting global variables and using global $variable in conventional functions.
November 14th, 2006 at 1:34 pm
I have made many significant improvements to this class, including the API, and many feature additions. The current link leads to the newest version, however I did maintain legacy versions for reference and nostalgia