Archive for July, 2010
Frameworks can make a developers life and job a lot simpler, but that doesn’t mean they don’t come with their own headaches and hours of frustration.
Tonight I’ve been coding an image uploading script using the CodeIgniter PHP Framework. This was the first time I’ve used the built-in image library to help me cut down my coding time.
Following the user guide at http://codeigniter.com/user_guide I was attempting to load an image that had been saved to the server, from the file uploading class. The example on the website uses the following example code:
$config['image_library'] = 'gd2'; $config['source_image'] = '/path/to/image/mypic.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();
This code actually doesn’t work, and will result in an error “Your server does not support the GD function required to process this type of image”.
Why doesn’t it work?
As posted on the CodeIgniter Forums by user ‘gunter’, you shouldn’t loop through
Instead what you should do is:
$this->load->library('image_lib'); // Set your config up $this->image_lib->initialize($config); // Do your manipulation $this->image_lib->clear();
(courtesy of a.somervell)
A lesson to show you that not even the documentation can always be correct. Hopefully this saves some people hours of pulling their hair out.