Posts tagged with thumb

Yii image helper

There are several image components already for Yii probably the most popular is the Kohana port one of the limitations this component has is that it cannot save thumbnails with adaptive resizing.

I have written a small helper class for PHPThumb the library included has a changed filename for Yii's autoloading.


The helper will allow for automatic caching of thumbnails, just make sure the directory is writeable, the thumb name is based on resize option and width / height and will be saved under a .tmb directory.

Simple example

This will create a thumbnail with adaptive resize width and height will be as specified and cropped from center.

<?php echo ImageHelper::thumb(600,800,'/upload/image.jpg');?>

Advanced example

This changes the resize method so the image will not be cropped enhances the quality settings for jpeg.


<?php echo Yii::app()->request->baseUrl.ImageHelper::thumb(600,800,$img, array(
	'method' => 'resize', 
	'quality' => 90));

With the 3rd parameter you can set any PHP Thumb setting look in the documentation for further information.