Codeigniter: Strange Image_lib error resolved

I was writing a CodeIgniter-based app which accepts an image (gif|jpg|png) from the browser and resizes it using calls to Image_lib.php library. Everything was going well on my development machine, even for large (1600×1200 pixels) JPEGs.

Then I got a call informing me that if you uploaded images greater than a certain width/height — size constraint was already in place — the script would fail. A blank page was returned.

I was puzzled since I distinctly remembered that we had taken in larger images before without any issues. I thought it might be the Upload.php library, but then no, the file was being uploaded successfully.

It took some determination to produce the stack trace:

blah::_resize('blah.jpg'); // in blah.php controller
Image_lib::resize(); // ... now in Image_lib.php library
Image_lib::image_create_gd('blah.jpg', 2); // some file, jpg image type
imagecreatefromjpeg(); // called by image_create_gd(): dies at this point

At this point I was sorely wishing that PHP had a better way of setting breakpoints than just using print_r and die. Best is to have a “Watched Expressions” feature so we can really figure out at which point did the script (abnormally) terminate.

Scroll down a little for the answer — my ex-colleague who is an experienced programmer gave me the answer, in like 3 minutes.


The problem was with the php.ini setting memory_limit. It was set to 8M on the staging server, whereas it was 16MB on my development machine. Restarting Apache with the value set to 16MB solved the problem! Gah!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s