CodeIgniter Forums
Image resize problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Image resize problem (/showthread.php?tid=49312)



Image resize problem - El Forum - 02-14-2012

[eluser]Bigil Michael[/eluser]
Now iam uploading 5 images at a time. uploading is working perfectly, problem is in image resize. Only my first image is resized other 4 images are in actual size. my code is given below.
Code:
for($i=1;$i<=5;$i++)
                {
               if($_FILES['photo'.$i]['name']!=''){
                   //upload thumbnail
                    $config = array();
                    $config['file_name'] = 'image'.$i;
                    $this->load->library('upload');
                    $this->upload->initialize($config);
                    if ( ! $this->upload->do_upload('photo'.$i))
                    {
                        $data['alert'] = $this->upload->display_errors();
                        $this->load->view('admin/photos/add', $data);                    }
                    else
                    {
                        $upload_data = $this->upload->data();
                        $filename = $upload_data['file_name'];
                        $width = $upload_data['image_width'];
                        $height = $upload_data['image_height'];
                        $config1 = array();
                        $this->load->library('image_lib');
                        $config1['source_image'] = absolute_path().'gallery/'.$filename;

                            //resize image
                            $sizes = array('width' => $width, 'height' => $height, 'new_width' => 500, 'new_height'    => '');
                            $newsize = array();
                            $newsize = $this->image_lib->size_calculator($sizes);
                            $config1['maintain_ratio'] = TRUE;
                            $config1['width'] = $newsize['new_width'];
                            $config1['height'] = $newsize['new_height'];
                            $this->image_lib->initialize($config1);
                            $this->image_lib->resize();
                            $this->image_lib->clear();
      
                        $this->image_lib->initialize($config1);
                        $this->image_lib->resize();
                        $config1['maintain_ratio'] = FALSE;
   $config1['width'] = 100;
   $config1['height'] = 100;
   $config1['create_thumb'] = TRUE;
   $config1['thumb_marker'] = 'thumb_';
   $this->image_lib->initialize($config1);
   $this->image_lib->resize();

                        $this->Photos_model->save_image('photo'.$i,$filename);
                    }
                }
can anyone help me to solve my problem???

searched in forum got 1 thread ,it says place $this->load->library('image_lib');this code before for loop.
tried but no result.


Image resize problem - El Forum - 02-15-2012

[eluser]bibos[/eluser]
Hi,

try to clear $upload_data array at the end of the loop :

Code:
unset($upload_data);



Image resize problem - El Forum - 02-15-2012

[eluser]Bigil Michael[/eluser]
thanks for your help.
used your code. but the result is same.

when i remove the code for thumb
Code:
$config1['maintain_ratio'] = FALSE;
$config1['width'] = 100;
$config1['height'] = 100;
$config1['create_thumb'] = TRUE;
$config1['thumb_marker'] = 'thumb_';

all images will resize. So i think problem is in thumb generation.



Image resize problem - El Forum - 06-10-2012

[eluser]Unknown[/eluser]
use $this->image_lib->clear() at the end of your loop Smile


Image resize problem - El Forum - 06-12-2012

[eluser]Bigil Michael[/eluser]
but the result is same.


Image resize problem - El Forum - 06-13-2012

[eluser]Bigil Michael[/eluser]
can any one help me to solve this problem ?