Welcome Guest, Not a member yet? Register   Sign In
Why the resize cicle work only for first loop
#1

[eluser]Gewa[/eluser]
The script I have wrote makes thumb only for first loop of the cicle. Whats up? Any help?


Code:
$config['upload_path'] = './images/lokale/';
               $config['allowed_types'] = 'gif|jpg';
             $config['max_size'] = '2000';
            $config['max_width'] = '600';
             $config['max_height'] = '600';

               $config['overwrite'] =FALSE;
             $this->load->library('upload', $config);
               $i=1;



                   $data['my_box']="We have successfully uploaded the files ";

            while($i<=3){
             $field_name = "file".$i;
                 if($this->upload->do_upload($field_name)){


                   $data['my_box'] .="<a >";

                        $nkar_info=$this->upload->data();
                                    $image_name=$nkar_info['file_name'];
                                    $raw_name=$nkar_info['raw_name'];
                                    $ext=$nkar_info['file_ext'];
                                                $data['my_box'] .="$image_name was uploaded successfuly <br>";


                                  $res1['image_library'] = 'GD2';
                                        $res1['source_image'] = $nkar_info['full_path'];


                                       $res1['maintain_ratio'] = TRUE;
                                         $res1['width'] = 150;
                                             $res1['height'] = 150;
                                          $res1['create_thumb']=TRUE;
                                          $res1['thumb_marker']="_thumb";


                                        $this->load->library('image_lib', $res1);

                                    $thumbik = $this->image_lib->resize();







                                     if ( !$thumbik)
                               {
                             $data['my_box'].= $this->image_lib->display_errors();
                        }
                        else{
                            $data['my_box'].= "Thumb was created successfully";
                        }










                      $insert = array(
                       'lid' => "$lid" ,
                          'photo_name' => "$image_name" ,
                         'small_name' => $raw_name.'_'.$res1['thumb_marker'].$ext
                      );






                    $this->db->insert('local_photos', $insert);

               }
                else{
               $data['my_box'].= "shajze $i ";
                   $error=$this->upload->display_errors('<p>', '</p>');
                     $data['my_box'].=$error;


               }

           $i=$i+1;
                        $res1=array();




           }
#2

[eluser]pistolPete[/eluser]
Your code is pretty messed up, but what I see is that you load the image class more than once.
The user guide states:
Quote:The clear function resets all of the values used when processing an image. You will want to call this if you are processing images in a loop.
Code:
$this->image_lib->clear();
#3

[eluser]DIMM[/eluser]
I have still the same problem. $this->image_lib->clear(); does not help. An only one thumb is created, although variable 'source_image' changes on each loop of the cicle
Code:
$data['files'] = get_filenames($path);

      foreach($data['files'] as $file){

        $config['image_library'] = 'gd2';

        $config['source_image'] = $path.$file;
        $config['create_thumb'] = TRUE;
        $config['thumb_marker'] = '_thumb';
        $config['maintain_ratio'] = TRUE;
        $config['width'] = 200;
        $config['height'] = 135;

        $this->load->library('image_lib', $config);
        $this->image_lib->resize();
        $this->image_lib->clear();
      }
#4

[eluser]pistolPete[/eluser]
Read what I wrote above:
You are loading the library more than once!
Use this instead:
Code:
$this->image_lib->initialize($config);
#5

[eluser]DIMM[/eluser]
[quote author="pistolPete" date="1235886183"]Read what I wrote above:
You are loading the library more than once!
Use this instead:
Code:
$this->image_lib->initialize($config);
[/quote]
Thanks!
P.S.
The decision of problem appears hides in user guide Smile




Theme © iAndrew 2016 - Forum software by © MyBB