Search code examples
codeigniterimage-manipulationphp

resize() not working using Image manipulation class


I’ve been reading the docs and trying everything to make thumbs out of uploaded images but I can’t seem to find the problem.

Images are uploaded and saved correctly but thumbs are not, it fails with no error output. This is the code I’m using:

$data = $this->upload->data();

$config_image['image_library'] = 'gd';
$config_image['source_image'] = $data['full_path'];
$config_image['new_image'] = 'uploads/thumbs/';
$config_image['create_thumb'] = TRUE;
$config_image['maintain_ratio'] = TRUE;
$config_image['width'] = 750;
$this->load->library('image_lib', $config_image);

if ( !$this->image_lib->resize())
{
    $this->session->set_flashdata('message',  $this->image_lib->display_errors());
} 

Also, I want to resize images to fit max-width=750, but maintain the ratio. Is what I’m doing correct to achieve that? Thanks!


Solution

  • I know this is a little too late, but I recently had the same issue and solve it by initializing the class.

    The CodeIgniter example does not work, you have to load the class first:

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

    Then after setting the config you need, then you initialize the class like so:

    $this->image_lib->initialize($config);
    

    This worked for me right away.

    I'm posting this in case anyone else is having the same issue, so they solve it with CodeIgniter and not another library.