image

Convert Kohana Image Library to Yii
53 followers

Provides methods for the dynamic manipulation of images. Various image formats such as JPEG, PNG, and GIF can be resized, cropped, rotated and sharpened.

All image manipulations are applied to a temporary image. Only the save() method is permanent, the temporary image being written to a specified image file.

Image manipulation methods can be chained efficiently. Recommended order: resize, crop, sharpen, quality and rotate or flip

此库提供方法动态的处理图片。支持对 JPEG,PNG 和 GIF 格式的图片进行调整大小,剪裁,旋转和锐化。

所有对图片的处理都会应用到一个临时图像上面,但只有 save() 方法是永久的,它会把临时图像写入指定的图像文件中。

图像处理方法也可以用“串连(chained)”方式。推荐顺序为:大小,剪裁,锐化,质量和旋转或翻转。

Resources

Documentation

Requirements

  • Yii 1.0 or above

Installation

  • Extract image folder under protected/extensions
  • Extract helpers folder under protected

Usage

The following code is the component registration in the config file:

'import'=>array(
    ...
    'application.helpers.*',
    ...
),
 
 
'components'=>array(
'image'=>array(
          'class'=>'application.extensions.image.CImageComponent',
            // GD or ImageMagick
            'driver'=>'GD',
            // ImageMagick setup path
            'params'=>array('directory'=>'/opt/local/bin'),
        ),...
)

See the following code example:

$image = Yii::app()->image->load('images/test.jpg');
$image->resize(400, 100)->rotate(-45)->quality(75)->sharpen(20);
$image->save(); // or $image->save('images/small.jpg');

or

Yii::import('application.extensions.image.Image');
$image = new Image('images/test.jpg');
$image->resize(400, 100)->rotate(-45)->quality(75)->sharpen(20);
$image->render();

Documentation

Change Log

February 1, 2009

  • The use of Yii::import instead of require to load image driver
  • Change image driver filename

January 22, 2009

  • Initial release.

Total 20 comments

#6570 report it
Nafania at 2012/01/19 04:44am
Re: "Image file not found"

dave3011: you must use path, not url, i.e. /some/image/path.jpg, not http://someImage.path

#6569 report it
dave3011 at 2012/01/19 04:21am
"Image file not found"

After installation of this extenstion as described (both ways, image->load() and new Image() ), I get the error: **image file not found ** (in myapppath\protected\extensions\image\Image.php(78))

This is weird since I tried to resize an image with the full path: $image = new Image('http://SomeRandomPicFromTheWeb.jpg');

Any help is appreciated!

#6416 report it
Mr. T at 2012/01/09 05:46am
Some problem with GD.php

I solved this problem using client ini file in root directory...

#6414 report it
schmunk at 2012/01/09 03:31am
Apache config settings

I tried to add previous line before code, which does thumbnail, but it's not work...

Check if your webserver config allows modification of the memory_limit setting. Does the same error still appear?

#6409 report it
Mr. T at 2012/01/08 06:59am
Some problem with GD.php

Following code does thumbnail from image, which storage on server:

// $imagePathFull full path to image
// $imageX width
// $imageY height
// $imagePathNewFull full path to thumbnail
$imageResize = Yii::app()->image->load($imagePathFull);
$imageResize->resize($imageX, $imageY, Image::NONE);
$imageResize->save($imagePathNewFull);

Should I add

ini_set('memory_limit', '64M');

before?

UPD

I tried to add previous line before code, which does thumbnail, but it's not work...

#6408 report it
schmunk at 2012/01/08 06:45am
@Mr. T: Raise your memory limit

Look like you're trying to resize a larger image. Adjust your PHP memory_limit, eg. with ini_set().

#6407 report it
Mr. T at 2012/01/08 06:28am
Some problem with GD.php

Hello!

I use this extension for resize images in my gallery with images for desktop and I have sometimes error in error_log.log file like

[08-Jan-2012 09:36:27] PHP Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 2560 bytes) in /home/username/public_html/protected/extensions/image/drivers/GD.php on line 368

What can it be? What should I do to solve this problem?

#6124 report it
este at 2011/12/14 02:51pm
Transparent GIF bug (black background)

Is it possible to repair this bug for transparent GIF management in GD? This extension will always convert the background to black.

Guess you should use imagecolorallocatealpha()

Thank you!

#5779 report it
cass at 2011/11/12 09:04am
Suggestion

Could I suggest that the Image class gets renamed to EImage as Image can potentially clash with other application models?

Regards,

Cass

#5037 report it
Ripsnorta at 2011/09/08 10:56pm
Using Image in a Loop
When used in a loop it's an Fatal error: Cannot redeclare class Image_GD_Driver
 
update: Solved: Changing 'include' in line 123 in GD.php to 'include_once' helps. Don't know why the author used include.

That seems to have been fixed in the GD.php, but I did encounter the same issue on line 123 of Image.php where the author used require. Changing this to:

require_once("drivers/{$this->config['driver']}.php");

does the trick.

#4969 report it
persistence at 2011/09/02 02:01am
支持打水印功能watermarks

是否可以支持打水印功能?watermarks

#4953 report it
lornechang at 2011/08/31 10:03pm
How to use it in a loop?

When used in a loop it's an Fatal error: Cannot redeclare class Image_GD_Driver

update: Solved: Changing 'include' in line 123 in GD.php to 'include_once' helps. Don't know why the author used include.

#4543 report it
teuku at 2011/07/19 06:42am
i am kindda stuck - can please help me.

guys..i have done what the manual above says. included changing in the line 80 on the image_gd_driver.php file.

but after i put the script in the index.php (i want to put my picture in the fron pages) I encounter some proble

#4542 report it
teuku at 2011/07/19 06:42am
i am kindda stuck - can please help me.

guys..i have done what the manual above says. included changing in the line 80 on the image_gd_driver.php file.

but after i put the script in the index.php (i want to put my p

#4509 report it
ivica at 2011/07/15 12:00am
Great share

I just installed this extension for project I am working on for gallery module, and it is working perfect. I had my own small image library that I am using for simple image manipulation tasks(croping and resizing only), but for advanced functions, this is very nice to use, especially in Yii projects!

#4478 report it
elbek at 2011/07/12 11:00am
awesome

That is what i need like wideimage library.

thanks

#4199 report it
nayjest at 2011/06/15 12:15pm
+

I agree with Parcouss. Please, replace line 80 in Image_GD_Driver.php

$quality = CArray::remove('quality', $actions);

to:

if (array_key_exists('quality', $actions)) {
    $quality = $actions['quality'];
    unset($actions['quality']);                 
} else {
    $quality = null;
}
#3997 report it
Marina at 2011/05/25 03:57pm
Cannot redeclare class Image_GD_Driver in

I have this error when i use Image to save and resize more than one pic to my server

#3732 report it
parcouss at 2011/05/02 04:13pm
new stuff

Hi,

I used this extension (as I said in previous post) and changed some things:

  • added 3 new functions (emboss, negate, grayscale)
  • modified the imagemagick driver which is now really faster

You can take the code and use it or do whatever you want with. It's in my extension.

#3237 report it
parcouss at 2011/03/28 05:47am
excellent !

It's excellent ! Really good.

However, I don't like the need for the CArray.php file, and so for the helper folder.

I used your extension in another one, where I have removed this need (fileimagearbehavior). CArray is only needed for 1 function of 3 lines, used only twice (one call in each Image_*_Driver.php file).

You can see these two files or copy them if you don't want CArray.

Thanx for the work and this extension !

Leave a comment

Please to leave your comment.

Create extension