I was looking for extention to resize images , I found two (can be more)
1 img
2 image
I tried with first one got some errors(probabely you will not) so jumped to second one, it works. Now I'm gong to teach you how to work with img extention .
This extension is a module called image . we can save images sent by the view form. Also we can edit those images.
Fisrt of all we need to install the module download the extention here
Create new folder "modules" under "protected" folder(needn't if already exist) and create new folder "image" under created "modules" folder and extract extention files there.
Make other changes in main.php file as the extention page .
That code goes here
Then run installer calling,
index.php/image/
or
index.php?r=image if your URL format is not set to 'path'
This module create a folder called files created by it self when installing it's the place save uploaded images(Actually when you call the save method) .But i changed this to my place .You can change it in
protected/modules/image/components/ImgManager.php file find $imagePath variable and changed it to your place
I changed it as 'protected/images/'
Also it use a database table to record few details about uploaded image.
In my view file image field's code is..
About this 'CMultiFileUpload' widget see
Yii multiple file upload post.
Then in my controller
Catch the image file with CUploadedFile::getInstancesByName() method.
Tsis extension has many functionalities but here I tried to make one version(resized) with original image . But you can save many sizes with versioning functionality.
1 img
2 image
I tried with first one got some errors(probabely you will not) so jumped to second one, it works. Now I'm gong to teach you how to work with img extention .
This extension is a module called image . we can save images sent by the view form. Also we can edit those images.
Fisrt of all we need to install the module download the extention here
Create new folder "modules" under "protected" folder(needn't if already exist) and create new folder "image" under created "modules" folder and extract extention files there.
Make other changes in main.php file as the extention page .
That code goes here
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| 'import'=>array( ..... 'application.modules.image.components.*', 'application.modules.image.models.Image',),'modules'=>array( ..... 'image'=>array( 'createOnDemand'=>true, // requires apache mod_rewrite enabled 'install'=>true, // allows you to run the installer ),),'components'=>array( ..... 'image'=>array( 'class'=>'ImgManager', 'versions'=>array( 'small'=>array('width'=>120,'height'=>120), 'medium'=>array('width'=>320,'height'=>320), 'large'=>array('width'=>640,'height'=>640), ), ),), |
Then run installer calling,
index.php/image/
or
index.php?r=image if your URL format is not set to 'path'
This module create a folder called files created by it self when installing it's the place save uploaded images(Actually when you call the save method) .But i changed this to my place .You can change it in
protected/modules/image/components/ImgManager.php file find $imagePath variable and changed it to your place
I changed it as 'protected/images/'
Also it use a database table to record few details about uploaded image.
In my view file image field's code is..
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| //The important part is going here.. <div class="row"> <?php echo $form->labelEx($model,'product_images'); ?> <?php $this->widget('CMultiFileUpload',array( 'name'=>'product_images', 'accept'=>'jpg|png', 'max'=>5, 'remove'=>Yii::t('ui','Remove'), 'denied'=>'type is not allowed', //message that is displayed when a file type is not allowed 'duplicate'=>'file appears twice', //message that is displayed when a file appears twice 'htmlOptions'=>array('size'=>25), )); ?> <?php echo $form->error($model,'product_images'); ?> </div> |
About this 'CMultiFileUpload' widget see
Yii multiple file upload post.
Then in my controller
Catch the image file with CUploadedFile::getInstancesByName() method.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| $primary_product_image = CUploadedFile::getInstancesByName('product_images');foreach ($primary_product_image as $image => $pic) { $image_object=Yii::app()->image->save($pic,$pic->name,'original_images/'); // this image save in 'protected/images/original_images/' folder. $thumb=Yii::app()->image->loadThumb($image_object->id); $config=array('width'=>320,'height'=>160); $options=new ImgOptions(); $options=ImgOptions::create($config); $thumb->applyOptions($options); $thumb->save(Yii::getPathOfAlias('application').'/images/resized_images/'.'-'.$image_object->name.'-'.$image_object->id.'.'.$image_object->extension); } |
Tsis extension has many functionalities but here I tried to make one version(resized) with original image . But you can save many sizes with versioning functionality.
0 comments:
Post a Comment