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.
protected/extensionsSee 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 '';
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
Total 1 comment
Hello,
is this still supported? (working on 1.1.x)?
thanks,
--iM
Leave a comment
Please login to leave your comment.