make 2 thumbnails at once in codeigniter make 2 thumbnails at once in codeigniter codeigniter codeigniter

make 2 thumbnails at once in codeigniter


It's actually pretty easy...

function create_thumbs(){    $this->load->library('image_lib');    $path = "path/to/image/";    $source_image = "original.jpg";    $medium_image = "medium.jpg";    $small_image = "small.jpg";    // Resize to medium    $config['source_image'] = $path.$source_image;    $config['new_image'] = $path.$medium_image;    $config['width'] = 200;    $config['height'] = 200;    $this->image_lib->initialize($config);     if ( ! $this->image_lib->resize())    {        // an error occured    }    // Keep the same source image    $config['new_image'] = $path.$small_image;    $config['width'] = 50;    $config['height'] = 50;    $this->image_lib->initialize($config);     if ( ! $this->image_lib->resize())    {        // an error occured    }}


So you have a thumbnail_generator function, and say it takes parameters original_file_name, new_file_name, and thumbnail_size.

Just call it twice!

thumbnail_generator( original_file.jpg, new_file_sm.jpg, 300 );thumbnail_generator( original_file.jpg, new_file_xsm.jpg, 150 );


Just a little modification in the above answer. Add this in the beginning of your function

$this->load->library('image_lib');$this->image_lib->clear();

the previous config needs to be cleared