Cakephp ThumbnailHelper

This thumbnail helper is based on the one published by Studio Canaria. Additional features are multiple size caching and an extra method which is a truly drop-in replacement for $html->image().
Usage:

<?php

echo $thumbnail->image('picture.jpg', array(
'alt' => 'test thumbnail',
'width' => '100',
'height' => '75'
)
);

// result:
//

?>

Installation:

  • Download thumbnail.txt
  • Rename it to thumbnail.php and place it in /app/views/helpers/
  • download phpThumb()
  • Extract the phpThumb archive in a directory named /app/vendors/phpthumb/
  • Add Thumbnail’ to the helpers’ array your controller
  • Create a directory named thumbs’ in /app/webroot/img/. Make sure it’s writable for the webserver.

That’s it!
In the above example, the thumb helper will first check if there is a file named /app/webroot/img/thumbs/100×75/picture.jpg. If it isn’t there yet, it will instantiate phpThumb and create the thumbnail.
For more advanced usage, there’s also the render() method. It will give you the flexibility to use images located outside /app/webroot/img and also make use of most of the phpThumb options.
Advanced example:

<?php

$thumb = $thumbnail->render(
$data['Picture']['path'],
array(
'w' => 320,
'h' => 200,
'ra' => 10
),
'5271a9e66c99c84c092d7fd81cebcd57'
);

echo $html->image($thumb);

?>

This will generate a picture named /app/webroot/img/thumbs/320×200/5271a9e66c99c84c092d7fd81cebcd57.jpg, which is a 10 degrees rotated thumbnail of the original image specified with $data['Picture']['path'].