CodeIgniter Forums
Double resizing wont work - 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: Double resizing wont work (/showthread.php?tid=29250)



Double resizing wont work - El Forum - 04-04-2010

[eluser]AlexJ[/eluser]
Hello, I am trying to resize a image to a certain size AND create a thumb of a certain size, this bit of code does not seem to work, it creates the thumbnail with the given size, but it just leaves the original image untouched:

Code:
$this->load->library('image_lib');
                
                // Resize the resized image to a thumbnail
                $thumbnail = array();
                $thumbnail['source_image'] = $image;
                $thumbnail['width'] = $presets['thumbnail']['width'];
                $thumbnail['height'] = $presets['thumbnail']['height'];
                $thumbnail['thumb_marker'] = '_new_thumb';
                $thumbnail['maintain_ratio'] = $presets['thumbnail']['keep_aspect'];    
                $thumbnail['create_thumb'] = TRUE;
                
                $this->image_lib->initialize($thumbnail);                
                
                if(!$this->image_lib->resize())
                {
                    echo $this->image_lib->display_errors();
                }            
                
                $this->image_lib->clear();  
                
                // Resize the original image to the setting
                $large = array();
                $large['source_image'] = $image;
                $large['width'] = $presets['large']['width'];
                $large['height'] = $presets['large']['height'];
                $large['maintain_ratio'] = $presets['large']['keep_aspect'];
                
                $this->image_lib->initialize($large);            

                if(!$this->image_lib->resize())
                {
                    echo $this->image_lib->display_errors();
                }

It was a late night build so maybe I looked something over the head Wink Does someone see anything wrong with this code?

Thanks!


Double resizing wont work - El Forum - 04-04-2010

[eluser]AlexJ[/eluser]
Fixed it, didnt use the clear function because it doesnt seem to work well:

Code:
$this->load->library('image_lib');
                      
                // Resize the original image to the setting
                $config = array();
                $config['image_library'] = 'gd2';
                $config['source_image'] = $image;
                $config['width'] = $presets['large']['width'];
                $config['height'] = $presets['large']['height'];
                $config['maintain_ratio'] = $presets['large']['keep_aspect'];
                
                $this->image_lib->initialize($config);            
              
                $this->image_lib->resize();
                
                $config['create_thumb'] = TRUE;
                $config['width'] = $presets['thumbnail']['width'];
                $config['height'] = $presets['thumbnail']['height'];
                $config['maintain_ratio'] = $presets['thumbnail']['keep_aspect'];
                $config['thumb_marker'] = '_new_thumb';
                
                $this->image_lib->initialize($config);
                
                $this->image_lib->resize();