From PHP 4 to PHP 5.. PHP Fatal zlib error: imagepng()

Getting this error?

PHP Fatal error: imagepng() [function.imagepng]: gd-png: fatal libpng error: zlib error in example.php on line 10

Fix it easily by changing your compression variable of imagepng, imagegif or imagejpg/imagejpeg into a 1-10 ranged number – instead of the PHP 4 1-100 standard.

It should work smoothly now :)

12 Responses

  1. Joe

    It works like heaven. Thank you.

  2. Jatin

    Yes…the solution works. Had the same problem while migrating from php4 to php5


  3. vic

    thanks dude … my code works nicely now!

  4. fedora_rocks

    YES! thanks dude!

  5. David Barnes

    Actually, 10 causes this error too. Set it to 9 to fix this problem.

  6. Blake

    Hey Jamie, thanks for taking the time to post this. You came up quite high on Google for this error message. Within less than a minute of encountering it in a project I’m working on, I was able to remedy it, thanks to your post.


  7. RaYa

    Hey, thx.. i used 7 and its works fine ^^

  8. Pece

    Works with values 0-9.

  9. creed

    Thanks for the fix! Tried it with 9 (after it not working with 10) and it worked like a charm. Gotta love easy solutions! Thanks again!

  10. Vaibhav

    Thank you so much! This one problem took two days of my life away :/

  11. Sham

    Thank you for posting this, you’re a life saver!

  12. Pingback on

    Warning: imagepng() [function.imagepng]: gd-png: fatal libpng error: zlib error « Leonel Santos

Comments are closed, but feel free to @jhuskisson on Twitter with your thoughts.