iWi ¶
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()
- cache()
- adaptive()
Installation ¶
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
//'params'=>array('directory'=>'C:/ImageMagick'),
),
Usage ¶
// loading
Yii::import('ext.iwi.Iwi');
$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();
Deprecated ¶
$this->widget("ext.iwi.Resize");
Widget Resize is now derpecated.
Use adaptive()
method now.
Changelog ¶
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/
adaptive()
without cropFirst 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"]); } else { $newHeight = $height; $newWidth = round($newHeight / $this->image["height"] * $this->image["width"]); } if ($crop) { $this->resize($newWidth, $newHeight); return $this->crop($width, $height, "center"); } else { return $this->resize($newWidth, $newHeight); } } return false; }
Table prefix for
storage
tableOnce more improvement. By default
storage
table creating in db withouttablePrefix
. To fix that iniwi/models/Storage.php
change:public function tableName() { return 'storage'; }
To:
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', )); } }
To:
public function verifyTable() { if (!Yii::app()->getDb()->schema->getTable('{{storage}}')) { Yii::app()->getDb()->createCommand()->createTable("{{storage}}", array( 'key' => 'string', 'value' => 'text', )); } }
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?
Answer to kernel32ddl
Yes, it was fixed in last version(iwi-1.1.6.zip) see changelog.
You can see here diff Diff
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
toreturn $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');
very useful
i was looking for this extension. thanks.
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.