CodeIgniter Forums
Image multiple resize - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Image multiple resize (/showthread.php?tid=52772)



Image multiple resize - El Forum - 06-26-2012

[eluser]Kentish[/eluser]
Hello

Am trying to get several sizes out of an image that i upload.
I have used tried the resize() function but its resizing the uploaded image only once. i.e using the first configurations only.
Here is the code :

Code:
public function resize_file($filename)
{
    
        $configs = array();
        $configs[] = array('source_image' => 'uploads/'.$filename,
'new_image' => 'uploads/thumbs/thumb/thumb.jpg',
'width' => 120, 'height' => 120);

        $configs[] = array('source_image' => 'uploads/'.$filename,
'new_image' => 'uploads/thumbs/120x120/thumb.jpg',
'width' => 120, 'height' => 120, 'maintain_ratio' => FALSE);

        $configs[] = array('source_image' => 'uploads/'.$filename,
'new_image' => 'uploads/thumbs/160x90/thumb.jpg',
'width' => 160, 'height' => 90, 'maintain_ratio' => FALSE);

        $configs[] = array('source_image' =>'uploads/'.$filename,
'new_image' => 'uploads/thumbs/small/thumb.jpg',
'width' => 240, 'height' => 240);

        $configs[] = array('source_image' => 'uploads/'.$filename,
'new_image' => 'uploads/thumbs/medium/thumb.jpg',
'width' => 800, 'height' => 800);
        

         //Loop through the array to create thumbs
        
        foreach ($configs as $config) {
            $this->load->library('image_lib',$config);  
            $this->image_lib->resize();
        }}



Image multiple resize - El Forum - 06-26-2012

[eluser]Jason Hamilton-Mascioli[/eluser]
Add this line to your foreach loop

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



Image multiple resize - El Forum - 06-26-2012

[eluser]Kentish[/eluser]
I have added it but still same prob...


Image multiple resize - El Forum - 06-26-2012

[eluser]Otemu[/eluser]
Auto load the library, then use:

Code:
$this->image_lib->initialize($config);
instead of
Code:
$this->load->library('image_lib', $config);



Image multiple resize - El Forum - 06-26-2012

[eluser]Kentish[/eluser]
this one works, thanks to both Smile