Welcome Guest, Not a member yet? Register   Sign In
Multiple thumbnails just isn't happening.
#1

[eluser]JasonS[/eluser]
For some reason I cannot convert more than one thumbnail.
Code:
if ($this->upload->do_upload('picture1'))
            {
                $data = $this->upload->data();
                $db['picture1'] = $data['file_name'];
                
                $lib['image_library'] = 'gd2';
                $lib['create_thumb'] = TRUE;
                $lib['maintain_ratio'] = TRUE;
                $lib['width'] = 200;
                $lib['height'] = 200;
                $lib['new_image'] = getcwd() . '/web/uploads/profile_thumbs/'.$data['file_name'];
                $lib['source_image'] = $source.$data['file_name'];
                
                $this->load->library('image_lib', $lib);
                $this->image_lib->resize();
            }
            
            if ($this->upload->do_upload('picture2'))
            {
                $data = $this->upload->data();
                $db['picture2'] = $data['file_name'];
                                
                $lib['image_library'] = 'gd2';
                $lib['create_thumb'] = TRUE;
                $lib['maintain_ratio'] = TRUE;
                $lib['width'] = 100;
                $lib['height'] = 100;
                $lib['new_image'] = getcwd() . '/web/uploads/profile_thumbs/'.$data['file_name'];
                $lib['source_image'] = $source.$data['file_name'];
                
                $this->load->library('image_lib', $lib);
                echo $this->image_lib->display_errors();
            }

The second picture2 doesn't resize the image and doesn't display any errors. A picture is being uploaded. Any ideas what is happening here?
#2

[eluser]designfellow[/eluser]
Hi,
change upload field names as array and use foreach loop to generate thumbnails.
#3

[eluser]JasonS[/eluser]
Can you clarify this please. The filenames are in the db array. How would I use a foreach to loop through these thumbnails? I do not see how this would be much different to what I am doing now. If the 'if' statements are not working then why would a foreach loop?
#4

[eluser]pistolPete[/eluser]
You load the image library twice and you omitted calling resize() for the second image; try this instead:
User guide:
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();

Code:
if ($this->upload->do_upload('picture1'))
            {
                $data = $this->upload->data();
                $db['picture1'] = $data['file_name'];
                
                $lib['image_library'] = 'gd2';
                $lib['create_thumb'] = TRUE;
                $lib['maintain_ratio'] = TRUE;
                $lib['width'] = 200;
                $lib['height'] = 200;
                $lib['new_image'] = getcwd() . '/web/uploads/profile_thumbs/'.$data['file_name'];
                $lib['source_image'] = $source.$data['file_name'];
                
                $this->load->library('image_lib', $lib);
                $this->image_lib->resize();
                $this->image_lib->clear();
            }
            
            if ($this->upload->do_upload('picture2'))
            {
                $data = $this->upload->data();
                $db['picture2'] = $data['file_name'];
                                
                $lib['image_library'] = 'gd2';
                $lib['create_thumb'] = TRUE;
                $lib['maintain_ratio'] = TRUE;
                $lib['width'] = 100;
                $lib['height'] = 100;
                $lib['new_image'] = getcwd() . '/web/uploads/profile_thumbs/'.$data['file_name'];
                $lib['source_image'] = $source.$data['file_name'];
                
                $this->image_lib->initialize($lib);
                $this->image_lib->resize();
                echo $this->image_lib->display_errors();
            }




Theme © iAndrew 2016 - Forum software by © MyBB