CodeIgniter Forums
[RESOLVED]not looping image resize - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: [RESOLVED]not looping image resize (/thread-37589.html)



[RESOLVED]not looping image resize - El Forum - 01-14-2011

[eluser]Gerep[/eluser]
Hi people,

I'm trying to create thumbs in a loop but it only works for the first image file.

I added the
Code:
$this->image_lib->clear();
after
Code:
$this->image_lib->resize();

The method returns all the files I need in the loop but only generates the thumb for the first file.

Thanks in advance.


[RESOLVED]not looping image resize - El Forum - 01-14-2011

[eluser]Atharva[/eluser]
Make sure you are not loading the image_lib in loop.


[RESOLVED]not looping image resize - El Forum - 01-14-2011

[eluser]Gerep[/eluser]
I was doing that =(

How will I set the $config array? It changes the source every time in the loop.


[RESOLVED]not looping image resize - El Forum - 01-14-2011

[eluser]Atharva[/eluser]
You will load the lib outside the loop without $config array
Code:
$this->load->library('image_lib');

And in loop, you will set the $config options with
Code:
$this->image_lib->initialize($config);

Edit: By outside, I meant before loop.


[RESOLVED]not looping image resize - El Forum - 01-14-2011

[eluser]Gerep[/eluser]
Still not working. Only generating the first images thumb. =/

Code:
$this->load->library('image_lib');
            foreach($query->result() as $row)
            {
                $config['image_library'] = 'gd2';
                $config['source_image'] = $row->file_name;
                $config['create_thumb'] = TRUE;
                $config['maintain_ratio'] = TRUE;
                $config['new_image'] = './system/application/uploads/imagem/thumbs';
                $config['width'] = 100;
                $config['height'] = 100;

                $this->image_lib->resize();
                $this->image_lib->initialize($config);
            }

PS: I have deleted the rest of the code where I get the database information to keep it easier to read.


[RESOLVED]not looping image resize - El Forum - 01-14-2011

[eluser]Atharva[/eluser]
Nope, you are resizing it before initializing!

It should be
Code:
$this->image_lib->initialize($config);
$this->image_lib->resize();



[RESOLVED]not looping image resize - El Forum - 01-14-2011

[eluser]Unknown[/eluser]
Here you go, it should work for you:
Code:
$this->load->library('image_lib');
            foreach($query->result() as $row)
            {
                $config['image_library'] = 'gd2';
                $config['source_image'] = $row->file_name;
                $config['create_thumb'] = TRUE;
                $config['maintain_ratio'] = TRUE;
                $config['new_image'] = './system/application/uploads/imagem/thumbs';
                $config['width'] = 100;
                $config['height'] = 100;

                $this->image_lib->clear();
                $this->image_lib->initialize($config);
                $this->image_lib->resize();
            }



[RESOLVED]not looping image resize - El Forum - 01-14-2011

[eluser]Gerep[/eluser]
Thanks a lot guys...it work perfectly. =)