Yii 1.1: cimagemodifier

Implements class.upload image manipulation class into Yii framework.
19 followers

Implements class.upload into Yii framework.

Class.Upload written by Colin VEROT (http://www.verot.net/)

This PHP script uploads and manipulates images very easily. The perfect script to generate thumbnails or create a photo gallery! It can convert, resize and work on uploaded images in many ways, apply effects, add labels, watermarks and reflections and other image editing features. You can use it for files uploaded through an HTML form, a Flash uploader, or on local files. It uses the GD library. This script is released under the GPL Version 2. If your project is not GPL, commercial licenses are available.

CImageModifier changelog

1.1, April 9, 2014

1.0, November 18, 2010

  • Initial release.
  • class.upload.php v.0.30.

Requirements

GD library

Usage

  1. unpack extension into desired location
  2. connect CImageModifier extension:

connection way 1: In your config.php file, in the components section, add the following:

'imagemod' => array(
               //alias to dir, where you unpacked extension
    'class' => 'application.extensions.imagemodifier.CImageModifier',
),

connection way 2: in your code:

Yii::app()->setComponents(array('imagemod'=>array('class'=>'application.extensions.imagemodifier.CImageModifier')));
  1. Main usage for uploaded image:
$img = Yii::app()->imagemod->load($_FILES['form_field']);
if ($img->uploaded) {
    $img->image_resize          = true;
    $img->image_ratio_y         = true;
    $img->image_x               = 50;
    $img->file_new_name_body = md5($img->file_src_name);
    $img->process('/home/images');
    if ($img->processed) {
      echo 'image resized';
      $img->clean(); //delete original image
    } else {
      echo 'error : ' . $img->error;
    }
}

or for static image:

$img = Yii::app()->imagemod->load('path/to/image');
$img->image_resize          = true;
$img->image_ratio_y         = true;
$img->image_x               = 50;
$img->file_new_name_body = md5($img->file_src_name);
$img->process('/home/images');
if ($img->processed) {
    echo 'image resized';
    $img->clean();
} else {
    echo 'error : ' . $img->error;
}

Methods

setLanguage($string)

By default this extension uses language set in config.php of your project. But you can change it using

Yii::app()->imagemod->setLanguage('ru_RU');

You can see al supported languages in extension /lang dir.

Features

  • Multilingual
  • Big code samples library
  • Good documentation
  • Working with uploaded and static images
  • Will work in any desired unpack dir without rewriting aliases in import functions

Resources

Total 6 comments

#17251 report it
nirmalroka at 2014/05/15 08:57pm
Any supprot for yii2

Hi this extension is great and I have using this extension for my yii project for yii>2.0.

As yii2 is released and am working on Yii2 for new yii based project but but image manipulation this extension would be great one so let us know when it will be supported in yii2

#3823 report it
GOsha at 2011/05/11 01:52pm
@existente

This extension is only a wrapper to original Class.Upload class. I think that you are doing smth wrong with your code. Could you, please, show your code at pastebin?

#3816 report it
existente at 2011/05/10 04:53pm
Problem with this extension

Hello. I´m trying to resize images using this extension and there are certain jpg images that can´t be processed. I receive the message “error : Error in creating JPEG image from source.”. All of these problematic images have the x component of the size longer than the y component. When I realize this I rotated one of these images using the option of the Windows explorer context menu and when I reprocess the image there was no error. I rotate the image again in order to get the original state but now there was no error in reprocessing. This information tells something to you???

#3337 report it
GOsha at 2011/04/04 12:35pm
2 bartatamas:

OK! Thanks!

#3335 report it
b_t at 2011/04/04 08:32am
Correction

It took me some time to realize that I shouldn't set the 'imageman' name for the component if I use it as Yii::app()->imagemod->load('path/to/image')

Please correct it ;)

#2697 report it
jumamidin at 2011/01/30 01:58pm
where to put?

hello! every body! I am new in yii. I do not know where to put these part of codes. Will someone help me? Pliiiz....

connection way 2: in your code:

Yii::app()->setComponents(array('imagemod'=>array('class'=>'application.extensions.imagemodifier.CImageModifier')));

  1. Main usage for uploaded image:

$img = Yii::app()->imagemod->load($_FILES['form_field']); if ($img->uploaded) { $img->image_resize = true; $img->image_ratio_y = true; $img->image_x = 50; $img->file_new_name_body = md5($img->file_src_name); $img->process('/home/images'); if ($img->processed) { echo 'image resized'; $img->clean(); } else { echo 'error : ' . $img->error; } }

or for static image:

$img = Yii::app()->imagemod->load('path/to/image'); $img->image_resize = true; $img->image_ratio_y = true; $img->image_x = 50; $img->file_new_name_body = md5($img->file_src_name); $img->process('/home/images'); if ($img->processed) { echo 'image resized'; $img->clean(); } else { echo 'error : ' . $img->error; }

Methods ¶ setLanguage($string)

By default this extension uses language set in config.php of your project. But you can change it using

Yii::app()->imagemod->setLanguage('ru_RU');

Leave a comment

Please to leave your comment.

Create extension