Welcome Guest, Not a member yet? Register   Sign In
Image resize problem
#1

[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.
#2

[eluser]bibos[/eluser]
Hi,

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

Code:
unset($upload_data);
#3

[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.
#4

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

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

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




Theme © iAndrew 2016 - Forum software by © MyBB