Monday, September 15, 2008

Asido: A PHP Thumbnailer/ Resizer Class

I was using class.upload for some time until a resize function (framing) I was using didn't work properly on my new server setup. So I looked for other PHP image processing classes I can find, but I realized that there is nothing that is actively developed. I also tried phpThumb but I had problems when I used it on some shared hosts.


I like Asido because of it's simple API. Unfortunately, it also has some problems and the latest release on its website was April 2007 (outdated). The most updated version which is pure PHP5 can be downloaded on the project's SVN repository (click the Download GNU tarball link).

Lets's fix it!

Jpeg Quality
The API on the website didn't show how to adjust the quality when saving files as JPEG. It defaults to 80% quality which is quite low for my taste. So here's how to adjust the quality:


Resizing Quality
Another problem is the bad image quality when resizing using GD. There's a simple fix to this. Open and replace imageCopyResized with imageCopyResampled inside the __resize function:

Protected Function __resize(asido_tmp $tmp, $width, $height) {

// create new target
$_ = imageCreateTrueColor($width, $height);
imageSaveAlpha($_, true);
imageAlphaBlending($_, false);

$r = imageCopyResampled(
$_, $tmp->target,
$width, $height,
$tmp->image_width, $tmp->image_height

// set new target
$tmp->target = $_;

return $r;

That's it! now Asido works great! one function that I like about it is it's Frame function (which other classes don't have). What it does is create fixed size thumbnails (aspect ratio is maintained, and the empty spaces are filled with a background color).


  1. thank for that post. you have saved me from a lot of debugging. i like this future too.

  2. Amazing... I was just about to drop it and look for something else

  3. Thanks a lot for this blog. Save a lot of my time dealing with Asido.

  4. Fantastic... Now the clients happy (happier) :)

  5. Fantastic.. the quality tip is exactly what I was looking for.

  6. Thanks a lot,Fantastic.
    It Fix my problems

  7. Thanks !!!
    Спасибо !!!

  8. Thank you! Dziekuje ;)