I have a similar feature built into one of my CI applications. In my case, I need configuration files in another function, so I created separate versions.
Do not load the library several times. Once all is well. Just update the library with the new configuration every time.
$this->load->library('image_lib'); $configSize1['image_library'] = 'gd2'; $configSize1['source_image'] = '/path/to/image/mypic.jpg'; $configSize1['create_thumb'] = TRUE; $configSize1['maintain_ratio'] = TRUE; $configSize1['width'] = 400; $configSize1['height'] = 300; $configSize1['new_image'] = '400x300image'; $this->image_lib->initialize($configSize1); $this->image_lib->resize(); $this->image_lib->clear(); $configSize2['image_library'] = 'gd2'; $configSize2['source_image'] = '/path/to/image/mypic.jpg'; $configSize2['create_thumb'] = TRUE; $configSize2['maintain_ratio'] = TRUE; $configSize2['width'] = 200; $configSize2['height'] = 200; $configSize2['new_image'] = '200x200image'; $this->image_lib->initialize($configSize2); $this->image_lib->resize(); $this->image_lib->clear();
And so on. I believe that for the sake of memory, you could disable and reset the configuration file, as suggested above, but if you plan to use image resizing in separate controller methods, like me, I found it useful to keep them separate.
source share