Welcome Guest, Not a member yet? Register   Sign In
[RESOLVED]not looping image resize
#1

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

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

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

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

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

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

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

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

[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();
            }
#8

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




Theme © iAndrew 2016 - Forum software by © MyBB