Karl Wong
Karl Wong

Reputation: 605

Codeigniter image resize library not working properly

for($i=0; $i< count($data['upload_data']); $i++){

                //resize uploade image
                $config['image_library'] = 'gd2';
                $config['source_image'] = $data['upload_data'][$i]['full_path'];
                $config['new_image'] = $data['upload_data'][$i]['full_path'];
                $config['maintain_ratio'] = TRUE;
                $config['width']    = 700;
                $config['height']   = 700;

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

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

I want to resize the images in a loop, all the images are already in the database, but after running this script, only the first image is resized.

All the path are correct, anyone else encountering this problem?

Upvotes: 1

Views: 870

Answers (1)

Jens A. Koch
Jens A. Koch

Reputation: 41796

After loading image_lib you might need to initialize it.

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

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

See: https://ellislab.com/codeigniter/user-guide/libraries/image_lib.html

You will NOT need to use the $this->image_lib->initialize function if you save your preferences in a config file.

Upvotes: 1

Related Questions