Yii 1.1: iwi

Web image crop and resize module. You use original image, set size and resize/crop type and there you go.


Idol Web Image module for adaptive image resizing and caching in database, based on Kohana Image module.

Next methods are available:

  • crop()
  • rotate()
  • flip()
  • sharpen()
  • quality()
  • render()
  • save()

Detailed documentation

  • cache()
  • adaptive()

Additional tags


1.Place 'iwi' folder into 'protected/extensions/'

2.Configuration (protected/config/main.php):

'iwi' => array(
    'class' => 'application.extensions.iwi.IwiComponent',
    // GD or ImageMagick
    'driver' => 'GD',
    // ImageMagick setup path


// loading
$picture = new Iwi('images/sample.jpg');
$picture->resize(100,100, Iwi::NONE);
echo $picture->cache();
// chainable usage in template
echo Yii::app()->iwi->load("images/totem.png")->adaptive(250,120)->cache();



Widget Resize is now derpecated. Use adaptive() method now.


November 03, 2012

  • Added support of tablePrefix. Requested by the user: kernel32ddl
  • Fix error if image doesn't exist

May 17, 2012

  • adaptive() combination of resize & crop, helps to making thumbnail.

May 15, 2012

Version 1.1 release
New api
ImageMagick support
There is no need to perform a dump, it is performed automatically

May 10, 2012

SQLite database support

May 4, 2012

Release of 1.0 version

Find us

Find us on GitHub : https://github.com/Idol-IT/iwi

For more info or advanced functions contact us : http://idol-it.com/

Total 6 comments

#16813 report it
rajesh chaurasia at 2014/03/31 06:51am
very useful

i was looking for this extension. thanks.

#10589 report it
kernel32ddl at 2012/11/06 06:30am
image type not allowed

Oh! Now I see it, thank you!

But such error is issued if image exists but corrupted, to prevent it I replace throwing CException to return $this:

// Check to make sure the image type is allowed
        if (!isset(Image::$allowed_types[$image_info[2]]))
            return $this; //throw new CException('image type not allowed');
#10588 report it
monkeymafia at 2012/11/06 06:14am
Answer to kernel32ddl

Fatal Error If Image Does Not Exists When Image Is Not Exists Fatal Error Issued: Fatal error: Call to a member function cache() on a non-object in \protected\views\model\view.php on line 216 Is any possibility to prevent that, because I work with images catalog that can consist corrupted images?

Yes, it was fixed in last version(iwi-1.1.6.zip) see changelog. You can see here diff Diff

#10587 report it
kernel32ddl at 2012/11/06 05:47am
Fatal Error if image does not exists

When image is not exists Fatal error issued: Fatal error: Call to a member function cache() on a non-object in \protected\views\model\view.php on line 216

<?php echo Yii::app()->iwi->load("$image->path")->resize(150,100,Image::AUTO)->cache(); ?>

Is any possibility to prevent that, because I work with images catalog that can consist corrupted images?

#10390 report it
kernel32ddl at 2012/10/25 01:11am
Table prefix for `storage` table

Once more improvement. By default storage table creating in db without tablePrefix. To fix that in iwi/models/Storage.php change:

public function tableName()
        return 'storage';


public function tableName()
        return '{{storage}}';

In iwi/Iwi.php from:

public function verifyTable()
        if (!Yii::app()->getDb()->schema->getTable('storage')) {
            Yii::app()->getDb()->createCommand()->createTable("storage", array(
                'key' => 'string',
                'value' => 'text',


public function verifyTable()
        if (!Yii::app()->getDb()->schema->getTable('{{storage}}')) {
            Yii::app()->getDb()->createCommand()->createTable("{{storage}}", array(
                'key' => 'string',
                'value' => 'text',
#10389 report it
kernel32ddl at 2012/10/25 12:51am
`adaptive()` without crop

First of all thank you very much for this great module!

Method apaptive() have useful parameter $upscale

public function adaptive($width, $height, $upscale = false)

But I also need resize image without cropping and upscaling. To achieve this I and once more parameter to make apaptive() more flexible:

public function adaptive($width, $height, $upscale = false, $crop = true)
        if ($this->image) {
            if (!$upscale) {
                if ($width > $this->image["width"])
                    $width = $this->image["width"];
                if ($height > $this->image["height"])
                    $height = $this->image["height"];
            $width = intval($width);
            $height = intval($height);
            $widthProportion = $width / $this->image["width"];
            $heightProportion = $height / $this->image["height"];
            if ($widthProportion > $heightProportion) {
                $newWidth = $width;
                $newHeight = round($newWidth / $this->image["width"] * $this->image["height"]);
                $newHeight = $height;
                $newWidth = round($newHeight / $this->image["height"] * $this->image["width"]);
            if ($crop) {
                $this->resize($newWidth, $newHeight);
                return $this->crop($width, $height, "center");            
                return $this->resize($newWidth, $newHeight);
        return false;

Leave a comment

Please to leave your comment.

Create extension