Extension for easy creating and caching thumbnails on real time.

You don't need to create many types of thumbnails for images in your project. You can create a thumbnail directly in the View. Thumbnail will automatically cached. It's easy!


  • Easy to use
  • Support GD and Imagick
  • Automaticly thumbnails caching
  • Cache sorting to subdirectories
  • Support Retina displays
  • Based on Kohana Image Library.


  • Yii 1.1 or above
  • GD or Imagick


Note: Latest release and documentation are available from extension github page.

Installing and configuring

Extract the EasyImage folder under protected/extensions

Add the following to your config file components section:

    'easyImage' => array(
        'class' => 'application.extensions.easyimage.EasyImage',
        //'driver' => 'GD',
        //'quality' => 100,
        //'cachePath' => '/assets/easyimage/',
        //'cacheTime' => 2592000,
        //'retinaSupport' => false,

and the following to import section:

'import' => array(



$image = new EasyImage('/path/to/image.jpg');
$image->resize(100, 100);


  • string $file required - Image file path
  • string $driver - Driver: GD, Imagick


You can create a thumbnail directly in the View:

// Create and autocache
Yii::app()->easyImage->thumbOf('/path/to/image.jpg', array('rotate' => 90));
// or
Yii::app()->easyImage->thumbOf('image.jpg', array('rotate' => 90),  array('class' => 'image'));
// or
        'resize' => array('width' => 100, 'height' => 100),
        'rotate' => array('degrees' => 90),
        'sharpen' => 50,
        'background' => '#ffffff',
        'type' => 'jpg',
        'quality' => 60,

Note. This method return CHtml::image()


  • string $file required - Image file path
  • array $params - Image manipulation methods. See Methods
  • array $htmlOptions - options for CHtml::image()


Yii::app()->easyImage->thumbSrcOf('image.jpg', array('crop' => array('width' => 100, 'height' => 100)));

Note. This method return path to image cached.


  • string $file required - Image file path
  • array $params - Image manipulation methods. See Methods

Total 17 comments

#19636 report it
ravin at 2015/10/24 03:27am
exception Not an image or invalid image though image exists


I have used this extension in my project and it gives exception Not an Image or Invalid Image though image exists. the extension throws the exception on linux environment and on windows environment it works normal for the same image.

#18700 report it
Artur Zhdanov at 2014/12/14 07:39am

Try this

#18686 report it
Jim K at 2014/12/12 12:05pm
re: imagerotate available only with bunbled GD error

@Artur, "E: Unable to locate package php-gd-bundled" when I try apt-get. Is this package available from a different repo? It doesn't appear to be in standard repo's.

#18675 report it
Artur Zhdanov at 2014/12/12 02:43am

I think you should install package "php-gd-bundled".

#18673 report it
Jim K at 2014/12/11 03:42pm
imagerotate available only with bunbled GD error

If you are running you app under Ubuntu or Debian, you may have seen this message. I'm not exactly sure which Ubuntu php5 package release corrects this but it is no longer valid. The current php553 install includes a GD version that has imagerotate so you'll need to comment out these lines 230-232 in Image_GD.php

// if (!Image_GD::$_bundled) { // throw new CException('This method requires imagerotate, which is only available in the bundled version of GD'); // }

I'm now able to rotate images correctly. If you are running on php5.3 or earlier, I think the issue is real and imagerotate is only available where included in the PHP bundle. I ran across this as I develop on WAMP and deploy to LAMP on Ubuntu.

#16816 report it
turco_7 at 2014/03/31 08:03am
CGridView ?

Dear all,

Can we use this extension on CGridView? Any idea ?


#14919 report it
yasser at 2013/09/21 07:42am
default image


very nice extension I used to use Image extension but moving to this....I wanted to ask if it supports default image if the image was not found: example: when trying to resize user profile image if he user doesn't have an image the a default user.png will be returned....


#14570 report it
Artur Zhdanov at 2013/08/23 12:26pm
re: How to set it title ?

playdog, your code is correct. Result:

<img title="hola" src="/assets/easyimage/c/c8dc27197f545c9cd85160e3d4764a8d.jpg" alt="">

Maybe you are using the cache for the page?

#14569 report it
playdog at 2013/08/23 12:04pm
How to set it title ?

How to set it title ?

Yii::app()->easyImage->thumbOf($modelNovedades[0]['imagen'],array('resize' => array('height' => 236),'type' => 'jpg','quality' => 60),array('title'=>'hola'))
#14492 report it
Sampa at 2013/08/17 10:38am
Indeed easy

Was indeed very easy to use. I use it to scan my image folder,and then create thumbnails of each image that does not have a thumbnail then display the thumbnail as a link to the full size image. Easy to combine with with any javascript gallery.

    $imageFolder = "images/portfolio/"; 
    foreach(glob($imageFolder.'*') as $image){ //search our images/portfolio folder for images        
        $filename = str_replace($imageFolder,"",$image); //extract the filename+extension only
        $thumbnail = $imageFolder."thumbnails/".$filename; // thumbnail path
        if(is_file($image)){ //make sure no folder or such is included 
            if(!is_file($thumbnail)){ //if there is no thumbnail create one
                $crop = new EasyImage($imageFolder.$filename); //the image
                $crop->resize(75, 75); //new size
                $crop->save($imageFolder."thumbnails/".$filename); //save to thumbnail
            //echo the thumbnail as a link to the full size image and set title to the filename only
            echo CHtml::link(CHtml::tag('img',array(                
#14462 report it
DrMabuse at 2013/08/13 12:49pm
Some problems


                        $img = Yii::app()->easyImage->thumbOf($path.$photo->id.'.jpg',
                                'resize' => array('width' => 1280, 'height' => null),
                                'type' => 'jpg',
                                'quality' => 100
                        $imgNew = str_replace(array('/frontend/www',"<","=","img",'/>','src"','"','alt',' ',"'"),'',$img);
//                        CVarDumper::dump($imgNew);
//                        echo CHtml::image(Yii::app()->createAbsoluteUrl($path.$photo->id.'.jpg'));
                        echo CHtml::image(Yii::app()->createAbsoluteUrl($imgNew));

i wanna save some space on my server then i use your extension. but i have some reasons about your methods. first thing is your thumbOf or your thumbOfSrc doesn't return the right Url. Next thing is i dont understand how to build a retina img without double my images(this step i really doesnt want ).

My Way: My User upload big images like 3000px.... then i cache the size what i need with your extension. My Structure is backend and frontend in other folders. the i save my images in common and build symlink in my Frontend and Backend to my upload Folder then i use your extension to get the sizes what i need but only in Frontend to save Space.

#13260 report it
schmunk at 2013/05/19 08:14am
@leandro: Aliases

Your change request is good, but you can also fix your problem with this workflow.

#13258 report it
leandro at 2013/05/18 10:55am
Thank you

Thank you very much Artur for include this change in a future version!

Can I ask just one more change please? :)

I'm using Yii with Yiiboilerplate. The extensions path alias is different from an standard Yii application.

The EasyImage class imports this:


But with Yiiboilerplate, there are several extensions directories for the different applications (for frontend, backend, console and common).

I need change the above lines with:


Could the extension alias be configurable too please?

Thank you! Leandro

#13257 report it
Artur Zhdanov at 2013/05/18 08:34am
Absolute path

Leandro, thanks for your comment! I'll do it at nearest time.

#13256 report it
leandro at 2013/05/18 08:17am
Images with absolute path not supported?

Hi, excellent extension.

However, I got a "file name can't be empty" error if I use:

$thumbnail = new EasyImage($absoluteImagePath);

This error is due the EasyImage constructor uses this:

dirname(Yii::app()->basePath) . $file

However, I am using EasyImage from a console command (images are generated asynch) and I need read the images from a different directory and save the thumbs on a different directory.

If I remove "dirname(Yii::app()->basePath)" from EasyImage above line, works like a charm.

Can you add more flexibility regarding paths please?

Thank you, Leandro

#13235 report it
schmunk at 2013/05/16 01:59pm
Looks nice!

+1 for composer support ;)

#13233 report it
le_top at 2013/05/16 01:45pm

Not tested, but will be coming back to this extension ;-).

If not done:

  • Automatic detection of 'driver' (check installed extension and cache the value).
  • Use 'width' and 'height' from the array directly for the resizing [where possible, use parameters provided to regular CHtml::image call];
  • Propose replacement for CHtml::image. Hint: I have my own YHtml class which extends CHtml. I would put a replacement for 'image' in there.

Leave a comment

Please to leave your comment.

Create extension
No downloadable files yet