Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter image resize?

I have problem with image class in CI?

This is example

On controller:

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

On view i have this:

    foreach($results as $row)
        {

$config['image_library'] = 'gd2';
$config['source_image'] = '/img/proizvodi/'.$row->proizvodid.'.jpg';
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width']     = 75;
$config['height']   = 50;


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

But i got no error, and thumb image is not created? I dont know where is mistake?

like image 335
Miomir Dancevic Avatar asked Oct 07 '13 06:10

Miomir Dancevic


1 Answers

You shouldn't load image_lib in foreach. Try to use code below

$this->load->library('image_lib');
foreach($results as $row) {
    $config['image_library'] = 'gd2';
    $config['source_image'] = '/img/proizvodi/'.$row->proizvodid.'.jpg';
    $config['create_thumb'] = TRUE;
    $config['maintain_ratio'] = TRUE;
    $config['width']     = 75;
    $config['height']   = 50;

    $this->image_lib->clear();
    $this->image_lib->initialize($config);
    $this->image_lib->resize();
}

If it wont work - check the upload folder permissions.

like image 59
Andrei Zhamoida Avatar answered Nov 13 '22 06:11

Andrei Zhamoida