Cool Image Thumbnail Class
Back in May, GenXDesign, released their PHP Thumbnail Class. Ok, so it’s not exactly “hot” news, it’s still an interesting piece of code.
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.
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
They even have a demo page with several samples, including the cute little fellow on the right.
The class is available in 2 flavors, PHP 4 and PHP 5. It is licensed under the MIT license.
=C=

Comments
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 ;)
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.