Yii 1.1: simpleimage

Simple extension to resize image

Most of time we just need resize function in a image library. This extension uses simple_image to resize image.


Yii 1.1 or above


extract download file to protected/extensions

Edit main.php

                        'class' => 'application.extensions.CSimpleImage',


$img = Yii::app()->simpleImage->load($file);


For more information: http://www.white-hat-web-design.co.uk/blog/resizing-images-with-php/

Total 16 comments

#19235 report it
luckyguy354 at 2015/04/25 09:13am
Why new extension?


I already tried 'image' extension which exported from Kohana, but it have problem with multiple file upload (CUploadedFile). I always get this error if I upload 2 images or more

Fatal error: Cannot redeclare class Image_GD_Driver in /home/user/public_html/protected/extensions/image/drivers/GD.php on line 380

I tried to unset every variable for each loop, but still got these error.

But this extension (simpleimage) work perfectly for CUploadedFile.

#11920 report it
Cozumel at 2013/02/13 01:47am
Property "CWebApplication.simpleImage" is not defined

If you get this error make sure that you've placed

                    'class' => 'application.extensions.CSimpleImage',

In the correct place and not in the middle of another array ( ),

Great extension, thanks!

#10145 report it
yasen at 2012/10/07 11:31am
Save Method Improvement

I've changed simple_image::save() as follows:

function save($filename, $image_type=false, $compression=75, $permissions=null) {
  $image_type = $image_type ? $image_type : $this->image_type;

This way saving a non-jpg image will not require adding image type parameter when calling save().

Edit: Adding at the end of the methods:

return $this;

one may do calls like

#9579 report it
cass at 2012/08/24 12:41pm

I appreciate this may go beyond of what the extension originally wanted to achieve, but I had to crop a few images and instead of adding yet another extension, I added the following method to this one:

function crop($startX, $startY, $width , $height) {
      $new_image = imagecreatetruecolor($width, $height);
      imagecopyresampled($new_image, $this->image, 0, 0, $startX, $startY, $width, $height, $width, $height);
      $this->image = $new_image;   

Might come in handy for someone, I presume.



#7567 report it
javad at 2012/03/30 10:48am
solve problem



     'class' => 'ext.resizeImage.CSimpleImage'
$file = "images/logo.jpg";
$img = Yii::app()->simpleImage->load($file);
#5861 report it
enfield at 2011/11/21 02:41am
Still not working.

Hi DavidTran, thanks for the quick response. I have changed every instance of the name to simpleImage and it does not work. This is after I tried your code as provided.

This is is consistent no matter what I try to change to get things to work. Property "CWebApplication.simpleImage" is not defined.

I appreciate you putting this together and it is something I could really use so it would be nice to understand how to get it working.

#5860 report it
David T at 2011/11/21 01:43am
simple image

The name simpleImage is defined in protected/config/main.php

                    'class' => 'application.extensions.CSimpleImage',

if you can the file in simple_image.php to simpleImage.php. You need to change CSimpleImage.php to reflex that change

#5857 report it
enfield at 2011/11/21 12:04am
Property "CWebApplication.simpleImage" is not defined.

I changed every simple_image to simpleImage also in trying to overcome this.


    $img = Yii::app()->simpleImage->load($file);

Is this because of my folder structure?

$homePath      = dirname(__FILE__) . '/../..';
$protectedPath = _joinpath($homePath, 'protected');
$webrootPath   = _joinpath($homePath, 'webroot');
$runtimePath   = _joinpath($homePath, 'runtime');

if so what do I need to change in the extension to make it work for me?

#5141 report it
suriyansuresh at 2011/09/18 07:35am
I fixed that issue

add <?php at the top line in simple_image.php
please update the extension

#5140 report it
suriyansuresh at 2011/09/18 07:25am
Please check my previous comment

I have tried that line also

#5138 report it
David T at 2011/09/18 06:29am

I am sorry when I gave the wrong class name. You just replaced this line:

$img = Yii::app()->simple_image->load($file);

To this:

$img = Yii::app()->simpleImage->load($file);

This would make the extension run properly.

#5137 report it
suriyansuresh at 2011/09/18 05:55am
Error persists

Can you fix this issue

Property "CWebApplication.simple_image" is not defined.

I copied CSimpleImage.php and simple_image.php to extensions folder

Here is my configuration

'components' => array(
'file' => array( 'class' => 'application.extensions.file.CFile', ),

    'simpleImage' => array(
        'class' => 'application.extensions.CSimpleImage',
public function actionTest() {  
    $file = "images/logo.jpg";  
    $img = Yii::app()->simple_image->load($file);  
  //  $img = Yii::app()->simpleImage->load($file); i have tried this line also  
#5136 report it
David T at 2011/09/18 05:36am

hi suriyansuresh, I place file in \protected\extensions\CSimpleImage.php. please fix your path.

#5134 report it
suriyansuresh at 2011/09/18 02:36am
Fatal Error

Class 'simple_image' not found in C:\wamp\www\mysite\protected\extensions\simple_image\CSimpleImage.php on line 14

#5126 report it
David T at 2011/09/16 04:49am
Because it simple

Reason I add new extension: - It simple and very easy to use - Lightweight and your page will load faster

Most of time, I just need to resize image.

#5124 report it
Maciej Liżewski at 2011/09/16 04:08am
Why new extension?

Why new extension? There is already http://www.yiiframework.com/extension/image ehich is much more powerful than just resize...

Leave a comment

Please to leave your comment.

Create extension
  • Yii Version: 1.1
  • License: New BSD License
  • Developed by: David T
  • Category: Others
  • Votes: +16
  • Downloaded: 2,953 times
  • Created on: Sep 16, 2011
  • Last updated: Sep 18, 2011
  • Tags: image