Most of time we just need resize function in a image library. This extension uses simple_image to resize image.
Yii 1.1 or above
extract download file to protected/extensions
Edit main.php
'components'=>array( 'simpleImage'=>array( 'class' => 'application.extensions.CSimpleImage', ),
Usage
$file="images/logo.jpg"; $img = Yii::app()->simpleImage->load($file); $img->resizeToWidth(128); $img->save("newLogo.jpg");
For more information: http://www.white-hat-web-design.co.uk/blog/resizing-images-with-php/
Total 15 comments
If you get this error make sure that you've placed
In the correct place and not in the middle of another array ( ),
Great extension, thanks!
I've changed simple_image::save() as follows:
This way saving a non-jpg image will not require adding image type parameter when calling save().
Edit: Adding at the end of the methods:
one may do calls like
I appreciate this may go beyond of what the extension originally wanted to achieve, but I had to crop a few images and instead of adding yet another extension, I added the following method to this one:
Might come in handy for someone, I presume.
Cheers,
Cass
protected/extensions/resizeImage/CSimpleImage.php
protected/extensions/resizeImage/simple_image.php
Hi DavidTran, thanks for the quick response. I have changed every instance of the name to simpleImage and it does not work. This is after I tried your code as provided.
This is is consistent no matter what I try to change to get things to work. Property "CWebApplication.simpleImage" is not defined.
I appreciate you putting this together and it is something I could really use so it would be nice to understand how to get it working.
The name simpleImage is defined in protected/config/main.php
'simpleImage'=>array( 'class' => 'application.extensions.CSimpleImage', ),if you can the file in simple_image.php to simpleImage.php. You need to change CSimpleImage.php to reflex that change
I changed every simple_image to simpleImage also in trying to overcome this.
view:
Is this because of my folder structure?
if so what do I need to change in the extension to make it work for me?
add <?php at the top line in simple_image.php
please update the extension
I have tried that line also
I am sorry when I gave the wrong class name. You just replaced this line:
To this:
This would make the extension run properly.
Can you fix this issue
Property "CWebApplication.simple_image" is not defined.
I copied CSimpleImage.php and simple_image.php to extensions folder
Here is my configuration
'components' => array(
'file' => array( 'class' => 'application.extensions.file.CFile', ),
'simpleImage' => array( 'class' => 'application.extensions.CSimpleImage', ), .... public function actionTest() { $file = "images/logo.jpg"; $img = Yii::app()->simple_image->load($file); // $img = Yii::app()->simpleImage->load($file); i have tried this line also $img->resizeToWidth(128); $img->save("newLogo.jpg"); }hi suriyansuresh, I place file in \protected\extensions\CSimpleImage.php. please fix your path.
Class 'simple_image' not found in C:\wamp\www\mysite\protected\extensions\simple_image\CSimpleImage.php on line 14
Reason I add new extension: - It simple and very easy to use - Lightweight and your page will load faster
Most of time, I just need to resize image.
Why new extension? There is already http://www.yiiframework.com/extension/image ehich is much more powerful than just resize...
Leave a comment
Please login to leave your comment.