Have an images gallery?
Tired of thinking what images sizes will you need?
Waste your time changing sizes and regenerating images?
This simple extension allows you to forget about this problems.
All you will need is to keep base (original) image.
Resizer extension will generate image whatever size you need, just on fly!
You will need:
urlManager urlFormat must be set to pathMove extension to /protected/extensions/resizer/
To use this extension you will need some controller. Extension is installed as controller action. Let's assume our controller name is test, and we will use resized action as name.
In your controller you need to add:
public function actions() { return array( 'resized' => array( 'class' => 'ext.resizer.ResizerAction', 'options' => array( // Tmp dir to store cached resized images 'cache_dir' => Yii::getPathOfAlias('webroot') . '/assets/', // Web root dir to search images from 'base_dir' => Yii::getPathOfAlias('webroot') . '/', ) ), ); }
Let's assume you have an image http://domain/images/big.png.
To get 100x100 icon, use the following URL :
http://domain/test/resized/100x100/images/big.png
So, as you see, URL structure is:
http://SERVER_NAME/CONTROLLER_ID/ACTION_ID/WIDTHxHEIGHT/PATH_TO_IMAGE
May have some bugs. Please, report them or ask questions.
Total 4 comments
Hi. When i tried to load images from default directory of images - it calls "images" an image was loaded perfectly. But when i tried to load image from "images/profile" i get a strange error : Unable to open 'somepath/assets/04c460b1cdecb0fe3357eca3f51283eb_100x100.IMAGES/PROFILE/9' for writing: No such file or directory (mypath/protected/extensions/resizer/index.php:225) (somepath and mypath is for example) So, i go to index.php and find problem in 57 string:
And i change it to
And image was loaded successfully. But I'm still grateful for the extension.
I think it would be good idea to add crop resize option. So image could be resized to say, square while keeping pixel aspect ratio. So one could create gallery with thumbs in same size and not distorted.
With cache. Each request actually runs thru Yii, so it's easy to cache and to detect changes. Drawback is that for each thumb php has to be executed. Well, with direct generating images it is more efficient, but way more comlicated.
Hi, pmaselkowski
filesize($original_image)) to cache key.I will add test page in future if community will be interested.
Regards, Bogdan
Well i have some questions, as i was doing similar approach recently.
Leave a comment
Please login to leave your comment.