I am new to Codeigniter. This is what I want to do:
- User uploads a profile picture.
- I resize the original image to several sizes, e.g. 400×300, 200×200, and 32×32.
But what I when I upload the image is that it’s re-sized successfully only for one dimension, 400×300.
Here is my code:
$config['image_library'] = 'gd2';
$config['source_image'] = '/path/to/image/mypic.jpg';
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 400;
$config['height'] = 300;
$config['new_image'] = 400x300image;
$this->load->library('image_lib', $config);
$this->image_lib->resize();
$this->image_lib->clear()
$config['image_library'] = 'gd2';
$config['source_image'] = '/path/to/image/mypic.jpg';
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 200;
$config['height'] = 200;
$config['new_image'] = 200x200image;
$this->load->library('image_lib', $config);
$this->image_lib->resize();
$this->image_lib->clear()
$config['image_library'] = 'gd2';
$config['source_image'] = '/path/to/image/mypic.jpg';
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 32;
$config['height'] = 32;
$config['new_image'] = 32x32image;
$this->load->library('image_lib', $config);
$this->image_lib->resize();
$this->image_lib->clear();
I tried using different config names like $config2 and $config3 but I did’t get the output.
Please help me to solve the issue.
I have a similar function built into one of my CI apps. In my case, I needed the config files in another function, so I built separate versions.
Don’t load the library multiple times. Once is fine. Just reinitialize the the library with your new config each time.
And so on. I suppose, for memory’s sake, you could unset and reset the config file, as was suggested above, but if you plan on using the image resizing in separate controller methods as I did, I found it helpful to save those separately.