Yii 1.1: image-cache

Dinamically generates transforms of given images, caching them

This extension is a initial (and fast) port of ImageCache from Drupal, pretending that generate thumbnails, rotated images, watermarks and in general, transforms of any kind for images using a pluggable toolkit (currently supported only GD2), will be as easy as define the preset in your config file and apply them in code.




  • Yii 1.0 or above


  • Extract the release file under protected/extensions


See the following code example: * Add this to your config file:

                    'scaleAndCrop'=>array('width'=>100, 'height'=>75),
                    'watermark'=>array('pngWatermark'=>'/images/watermark.png', 'x'=>50,'y'=>25),
                'actions'=>array( 'scaleAndCrop'=>array('width'=>40, 'height'=>30) ),
                'actions'=>array( 'scaleAndCrop'=>array('width'=>27, 'height'=>20) ),

Basic explanation: you can create as many presets as you want, in this case I have created one named "thumbs"
that caches files in the dir "webroot / imagecache", and for this preset I added two actions: scaleAndCrop and later rotate. Currently (look at the code) I support: [b]resize, scale, scaleAndCrop, rotate and crop and watermark[/b]

  • For testing: create a controller and add for example this action:

    public function actionFile() { $thumb = Yii::app()->image->createUrl( 'thumbs', // the preset we have configurated YiiBase::getPathOfAlias('webroot.files').'/X TRILE1.JPG'); // An image file!!! if ($thumb) print ''; else print "bad"; }

  • Invoke your action: first time, the api will create the image and caches in the specified dir rest, simply returns the cached images so... it's very fast


  • api for purgue the cached images
  • do as many actions as Drupal ImageCache???? :P
  • open a serious project instead of a forum post

Change Log

October 2, 2009

  • Initial release.

December 9, 2009

  • Added watermarking and refactored

Total 1 comment

#318 report it
imehesz at 2010/07/10 11:42am


is this still supported? (working on 1.1.x)?



Leave a comment

Please to leave your comment.

Create extension
  • Yii Version: 1.1
  • License: New BSD License
  • Developed by: Hwangar
  • Category: Others
  • Votes: +7
  • Downloaded: 1,476 times
  • Created on: Oct 2, 2009
  • Last updated: Dec 9, 2009