KP Solutions

Solutions for Day to Day Technical Problems

php createimagefromjpeg fails without error


I guess you have an issue while you try to create thumbnail from a jpg, merge two jpgs or crop a jpg. Issue is that @createimagefromjpg fails without any reason on a code like this

$srcImage = @createimagefromjpeg($filePath);

Now, if you look up php documentation for error control, you would see that ‘@’ sign is culprit. It suppresses all the warnings and errors. Don’t use it unless you are 100% sure that you don’t want any errors from it. I found out that since ‘@’ sign was there, I didn’t see any errors in any of my logs. Now, once I removed the ‘@’ from ‘@createimagefromjpeg($filePath)’, I saw exact error why the script wasn’t able to process the jpg.

Most of the time the error would be one of the following:

  1. Source image file not found
  2. Memory limit is too low to process the image
  3. GD library support is not built in the php executable on your server.

Once, you know what error is, you can take an appropriate action to resolve it.

Like me, if you are using an open source library, sometimes it takes lot of pain to resolve a minor issue. First, thing to ensure is that if you see any of those ‘@’ char in front of any failing line, then remove it.

I recommend to avoid using ‘@’ char to suppress errors/warnings.

Hope to help,