Saturday, January 15, 2011

Strange GD error when working on PNG images from PHP on FreeBSD

I have a problem with my FreeBSD 7.1 server. PHP's GD implementation no longer works on PNG images. Whenever the system tries to work with PNG images, I get these three error messages:

[Sat Jul 18 21:41:15 2009] [error] [client 90.34.34.34] PHP Warning:  imagecreatefrompng() [function.imagecreatefrompng]: gd-png:  fatal libpng error: [00][00][00][00]: unknown critical chunk in /usr/storage/www/private/mikkel.hoegh.org/modules/acquia/imageapi/imageapi_gd.module on line 44, referer: http://mikkel.hoegh.org/admin/build/imagecache/3
[Sat Jul 18 21:41:15 2009] [error] [client 90.34.34.34] PHP Warning:  imagecreatefrompng() [function.imagecreatefrompng]: gd-png error: setjmp returns error condition in /usr/storage/www/private/mikkel.hoegh.org/modules/acquia/imageapi/imageapi_gd.module on line 44, referer: http://mikkel.hoegh.org/admin/build/imagecache/3
[Sat Jul 18 21:41:15 2009] [error] [client 90.34.34.34] PHP Warning:  imagecreatefrompng() [function.imagecreatefrompng]: 'sites/mikkel.hoegh.org/files/imagecache_sample.png' is not a valid PNG file in /usr/storage/www/private/mikkel.hoegh.org/modules/acquia/imageapi/imageapi_gd.module on line 44, referer: http://mikkel.hoegh.org/admin/build/imagecache/3

I've been trying to solve this half a day now, and the best clue I've found is another guy having the same problem – no solution there, though.

The code in question is fairly simple, it just calls imagecreatefrompng($filename);

Package versions of all the packages I can think of that might be related:

  • php5-5.2.10
  • php5-gd-5.2.10
  • png-1.2.37
  • gd-2.0.35_1,1

Any clues?

  • It could be problem with PNG image. Try very basic code with very small black and white PNG image. If that also generates same errors in log files then you could consider installing PHP from source so that modules like php_gd get updated to latest version.

    You can also try setting

    error_reporting  =  E_ALL
    display_errors = On
    

    in case they give some better error message on screen. Remember to make display_errors=Off after you have finished debugging on a production server.

    mikl : Well, it is the same with all PNG images I've tried. And as far as I can see, the error message is exactly the same whether you output it to the log or to the screen.
    Saurabh Barjatiya : Based on your distribution you would have some package manager like yum or apt. Try updating apache, php, php_gd using that package manager. If that does not works then I guess recompiling PHP from source would be the best option.
    mikl : The versions I mentioned are the latest available – I have tried the upgrade strategy already…
  • I had a recent problem similar to this. After upgrading one of the packages on my 7.2 system, the gd-driven captcha on my phpBB2 installation stopped working. I re-built all of the php ports and it fixed itself.

    I know that's a bit vauge, but sometimes things will break over months of incremental upgrades due to dependencies getting out of whack.

    mikl : Yeah, I already tried to rebuild php-gd with all of its dependencies. I think I might try something more… drastic. I have an upgrade to 7.2 I've been putting off for a while, so if I have to rebuild all my packages, that might be a good occation :)
  • No answer but since I cannot leave any comment; I have a 7.2 system with exactly the same problem and exactly the same versions. Even tried downgrading libpng to no avail. Doing a binary upgrade from 7.1. to 7.2 was extremely painless and well worth it but don't think that will fix the problem :-)

    I also installed pecl-imagick to see if I could use that instead but to my surprise I got similar errors. I tried lots of other software that depends on libpng but they could all load the images giving errors in php5-gd and pecl-imagick just fine. This made me exclude libpng, which at first I thought was the problem. My next guess is that something in the php API has changed, I will try to downgrade php and see if that helps.

    mikl : Okay, interesting – I've managed to get my image processing working by using imagemagic (the CLI util, not the pecl package). That could indicate that this might in fact be a PHP bug. *shakes tiny fist at PHP*
  • Before updating always read

    /usr/ports/UPDATING
    

    Sometimes you'll need to do recursive portupgrade i.e.

    portupgrade -fr png-1.2.37
    
    mikl : Was there anything in particular I should have noticed in UPDATING? I can't spot something related to this problem. I don't use portupgrade, but I'm running a `sudo portmaster -ru graphics/png` now to see if that'll fix it.
    mikl : Recursive rebuild did not fix the problem, sadly. I tried earlier by rebuilding all dependencies of php5-gd, but that had no effect either.
    SaveTheRbtz : maybe, as last resort, `portmaster -fa` will help?
    mikl : Thankfully, it has disappeared after I upgraded to FreeBSD 7.2. I think the decisive change was the complete rebuild of all packages. Thanks.
  • This command solve my problem:

    portupgrade -fr png-1.2.40

  • If you are using portmaster, this will work:

    portmaster -dbrR png-1.2.40
    
    From Markus

0 comments:

Post a Comment