CodeIgniter Forums
image_lib... how to scale image down and then create a thumb in one function? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: image_lib... how to scale image down and then create a thumb in one function? (/showthread.php?tid=7908)



image_lib... how to scale image down and then create a thumb in one function? - El Forum - 04-27-2008

[eluser]inktri[/eluser]
For every uploaded image I want to first: scale it down to 500x500 and then create a thumbnail (a new thumbnail file is created) of the image. The below code is what I use, unfortunately the result is... a 500x500 image is generated, most of it's black, in the top left corner there is a 150x150 scaled down version of the original. If I only do one operation at a time (by commenting out the other) everything works. What am I doing wrongly? Thanks for the help.

Code:
// resize original to smaller 500 500
            $resize_config['image_library'] = 'GD2';
            $resize_config['source_image'] = './images/photos/' . $photo_info['file_name'];
            $resize_config['maintain_ratio'] = TRUE;            
            $resize_config['create_thumb'] = FALSE;
            $resize_config['width'] = 500;
            $resize_config['height'] = 500;
            $this->load->library('image_lib', $resize_config);
            $this->image_lib->resize();                
            
            // create thumb
            $thumb_config['image_library'] = 'GD2';
            $thumb_config['source_image'] = './images/photos/' . $photo_info['file_name'];
            $thumb_config['maintain_ratio'] = TRUE;
            $thumb_config['new_image'] = './images/photos/t_' . $photo_info['file_name'];
            $thumb_config['thumb_marker'] = '';
            $thumb_config['create_thumb'] = TRUE;            
            $thumb_config['width'] = 150;
            $thumb_config['height'] = 150;
            $this->load->library('image_lib', $thumb_config);
            $this->image_lib->resize();



image_lib... how to scale image down and then create a thumb in one function? - El Forum - 04-27-2008

[eluser]wiredesignz[/eluser]
You need to reset the image library between tasks. Read the User Guide.


image_lib... how to scale image down and then create a thumb in one function? - El Forum - 04-27-2008

[eluser]mironcho[/eluser]
Hi inktri,
use initialize() method instead of second load->library. Check this thread:
http://ellislab.com/forums/viewthread/77795/

and image lib documentation:
http://ellislab.com/codeigniter/user-guide/libraries/image_lib.html