Welcome Guest, Not a member yet? Register   Sign In
image library - resizing images twice?
#1

[eluser]danielpetrie[/eluser]
I'm having issues resizing an image twice, I'm able to do it once fine, but when I try to resize it an image a 2nd time, it keeps and uses the initial config options. Whats happening, is I'm allowing a user to upload an image, then I want to keep that original image, make a medium size version of the image, and a thumbnail of the image. Here's my code from the controller.

Code:
$image_data = $this->upload->data();

$config = array(
’source_image’ => $image_data['full_path'],
‘new_image’ => $this->gallery_path . ‘/thumbs’,
‘maintain_ratio’ => true,
‘width’ => 150,
‘height’ => 150
);

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

$config2 = array(
’source_image’ => $image_data['full_path'],
‘new_image’ => $this->gallery_path . ‘/large’,
‘maintain_ratio’ => true,
‘width’ => 850,
‘height’ => 650
);

$this->load->library(’image_lib’, $config2);
$this->image_lib->resize();

So when this code is run, I end up having 2 images in the '/thumbs' folder both the same size instead of 1 in there, and 1 in the '/large' folder. Anyone know how to go about doing this?
#2

[eluser]stommert[/eluser]
Hi,
You might want to add this
Code:
$this->image_lib->clear()
between the two actions.
I hope it helps.
#3

[eluser]John_Betong[/eluser]
 
I agree with using $this->image_lib->clear() and would also try creating a thumbnail from the newly resized image.

The reason is it will have a reduced image file to process and may/should make performance difference.
 
 
 
edit: clarified double negative
#4

[eluser]danielpetrie[/eluser]
I was thinking there would be some command like that but couldn't find it. I'll give it a shot. Thanks for the help and tip.
#5

[eluser]k00k[/eluser]
I just ran into this same issue and wanted to share my experience.

After you're done with your first resize, call the following:

Code:
$this->image_lib->clear();

Then, instead of loading the image_lib library again, call:

Code:
$this->image_lib->initialize($config2); // load 2nd config

And then you can call the resize or what have you for the 2nd image.

Hope that helps someone, it tripped me up. I'd love to see it added to the manual in as much detail.
#6

[eluser]Mat-Moo[/eluser]
Check out my Image_moo lib make life easy for yourself! In my sig Smile




Theme © iAndrew 2016 - Forum software by © MyBB