Explore Yourself !!!


File upload in CI [Short Tip: Don't load library first]
May 22, 2009, 1:28 am
Filed under: Code Igniter | Tags: , ,

I found an interesting thing about CI file resize functionality. To resize an image we need to load image_lib library.

$this->load->library(‘image_lib’); //don’t use it

But if we load this library first and assign configuration variables later then it gives the following error:
Your server does not support the GD function required to process this type of image.\

instead first make ready your configuration variables and then load the library as

$config['image_library'] = ‘gd2′;
$config['source_image'] = ‘./existing/img/loc/aminul.jpg’;
$config['create_thumb'] = TRUE;
//$config['new_image'] = ‘./new/image/location/new_amin.jpg’; // you can assign your image name and location
$config['maintain_ratio'] = TRUE;
$config['width'] = 75;
$config['height'] = 50;

$this->load->library(‘image_lib’, $config);
if ( ! $this->image_lib->resize())
{
echo $this->image_lib->display_errors();
}

now it should work fine without any error in CI.


No Comments Yet so far
Leave a comment



Leave a comment
Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>