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.
Resources ¶
Documentation ¶
Requirements ¶
- Yii 1.0 or above
Installation ¶
- Extract the release file under
protected/extensions
Usage ¶
See the following code example:
Add this to your config file:
'image'=>array(
'class'=>'ext.imageapi.CImage', 'presets'=>array( '640x480'=>array( 'cacheIn'=>'webroot.repository.640x480', 'actions'=>array( 'scaleAndCrop'=>array('width'=>640, 'height'=>480), 'watermark'=>array( 'pngWatermark'=>'webroot.images.watermark.png', 'x'=>590,'y'=>430), ), ), '100x75'=>array( 'cacheIn'=>'webroot.repository.100x75', 'actions'=>array( 'scaleAndCrop'=>array('width'=>100, 'height'=>75), 'watermark'=>array('pngWatermark'=>'/images/watermark.png', 'x'=>50,'y'=>25), ), ), '40x30'=>array( 'cacheIn'=>'webroot.repository.40x30', 'actions'=>array( 'scaleAndCrop'=>array('width'=>40, 'height'=>30) ), ), '27x20'=>array( 'cacheIn'=>'webroot.repository.27x20', '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
ToDo ¶
- 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
support
Hello,
is this still supported? (working on 1.1.x)?
thanks,
--iM
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.