Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple resizing in CodeIgniter

I need to make two images of a single loaded picture. This images must have fixed width, - 180 and 300 pixels.

At the bottom of my current results. This function can resize and create just one of two images. Everybody failed on second image, I trying whole day, but I'm can't find reason. Need help.

$this->_resize($data['upload_data']['file_name'], 300);
$this->_resize($data['upload_data']['file_name'], 180);
private function _resize($file_name, $size) {
            $config['image_library'] = 'gd2';
            $config['source_image'] = 'img/upload/' . $file_name;
            $config['dest_image'] = base_url() . 'img/';
            $config['create_thumb'] = TRUE;
            $config['thumb_marker'] = '_' . $size;
            $config['maintain_ratio'] = FALSE;
            $config['width'] = $size;
            $config['height'] = $size;
            $this->load->library('image_lib', $config);
            $result = $this->image_lib->resize();

            $this->image_lib->clear();
            return;
        }

I'm use CodeIgniter 2.02

like image 417
NiLL Avatar asked Jul 03 '11 18:07

NiLL


2 Answers

Dont load image_lib multiple times. Add image_lib in autoload libs and change

$this->load->library('image_lib', $config);

to

$this->image_lib->initialize($config);
like image 50
Ali Hamza Avatar answered Oct 06 '22 09:10

Ali Hamza


This could help you, from user guide

A good practice is use the processing function conditionally, showing an error upon failure, like this:

if ( ! $this->image_lib->resize())
{
    echo $this->image_lib->display_errors();
}
like image 26
Ivan Ivanic Avatar answered Oct 06 '22 10:10

Ivan Ivanic