Pages

CodeIgniter image_lib bug in the image process loop

This bug has me scratch my head for hours and finally found the solutions to fix it.

In CodeIgniter, you can upload multiple images and do resize, crop and watermark stuff. It's cool that you can use one library to do many awesome stuff. However there is problem when using image_lib in the loop.

Problem:

I upload few image and want to loop through each one of them and resize them differently based on their original size. So I put the resize function in the loop. However, the dimension is based on the previous image.

For example. the first image is resized to 100x200. The second image should be resize to 50x100, but is resized to 100x200. The third one should be resized to 400x300, but is resized to 100x75.

In other words, the second image was resized using the dimension from the previous resized image based on the second image's longer side (W or H). The first image was resized to 100x200, so the second image was resized to 100x200 because the original dimension of the second image was 50x100 (Height is larger than width). So it take the first image's height to resize the second images. Crap!


Solutions:
In the image_lib in CodeIgniter, there is a function to clean the setting ($config). However, there is missing parameters in the function.

So I add two lines in the function clear().

$this->width = '';
$this->height = '';
Add the above two lines before closing the function.

Problem solved!

No comments:

Post a Comment

Thank you for your feedback. If you find the tip and trick useful, feel free to share with your friends on Facebook, Twitter and G+!