image-cache Dinamically generates transforms of given images, caching them

  1. Documentation
  2. Change Log

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 '<img src="'.$thumb.'" alt=""/>';
      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
6 0
1 612 downloads
Yii Version: 1.1
License: BSD-2-Clause
Category: Others
Developed by: Hwangar
Created on: Oct 2, 2009
Last updated: 13 years ago


show all