CodeIgniter Forums
Problem geting image resize to work - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Problem geting image resize to work (/showthread.php?tid=11316)



Problem geting image resize to work - El Forum - 09-03-2008

[eluser]old_guy[/eluser]
Most likely an obvious solution but I can't see it. I'm uploading an image file to a folder, resizing it and then writing the image path to a dB.

The original image upload works and the image path gets inserted in the dB but the image resize doesn't happen.

Hope some can help me see the what I'm not doing...code follows:

Uploading an image file as follows works fine:

$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['overwrite'] = 'TRUE';
$this->load->library('upload', $config);

I then run a function to resize the image as follows:

$this->load->library('image_lib');
$config['image_library'] = 'gd2';
$config['source_image'] = array('image' => 'uploads/' .element('file_name', $this->upload->data()));
$config['create_thumb'] = FALSE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 250;
$config['height'] = 250;
$this->load->library('image_lib', $config);
$this->image_lib->resize();

And, finally I upload the image path to the dB:

$img_path = array('image' => 'uploads/' .element('file_name', $this->upload->data()));
$this->db->where('id', $id);
$this->db->update('personal', $img_path);


Problem geting image resize to work - El Forum - 09-03-2008

[eluser]Rick Jolly[/eluser]
Remove the first "$this->load->library(’image_lib’);" and it should work fine.


Problem geting image resize to work - El Forum - 09-03-2008

[eluser]old_guy[/eluser]
Many thanks...simple solution in deed. BTW, you also can pass an array for 'source_image'.


Problem geting image resize to work - El Forum - 09-03-2008

[eluser]old_guy[/eluser]
correction: I could not pass an array for 'source image'