PHP fatal libpng error: zlib error
Posted November 4th, 2008 in PHP
While working with some image functions in PHP I changed the output image from JPEG to PNG (from the ImageJPEG to ImagePNG functions) and got the error message "gd-png: fatal libpng error: zlib error". This post looks at the cause of the error and the solution.
The full error message looks like this:
Fatal error: imagepng() [<a href='function.imagepng'>function.imagepng</a>]: gd-png: fatal libpng error: zlib error in /path/to/filename.php on line 123
My original code looked like this:
ImageJPEG($image, 'filename.jpg, 100);
and I simply changed the function name like this:
ImagePNG($image, 'filename.jpg, 100);
The third parameter is for the quality of the image. The images being generated are the highest quality possible which for JPEG images is a range from 0 (lowest quality, smallest file size) to 100 (highest quality, largest file size).
The reason for the error is that the quality range for the ImagePNG function is from 0 to 9 and anything outside that won't work. So simply change the value to between 0 and 9 and the error will go away.
Note that 0 means no compression and 9 means the highest compression possible i.e. the scale is reversed when compared with JPEG images.
Related posts:
- Image headers with PHP (Tuesday, July 22nd 2008)
- Get an image size with PHP (Wednesday, July 9th 2008)
- PHP error Call to undefined function ImageCreateFromPNG (Wednesday, January 9th 2008)
Recent posts:
- MySQL queries for article summaries part 2 of 2 (Tuesday, January 6th 2009)
- Aims for 2009 (Monday, January 5th 2009)
- Weekly Roundup - January 5th 2008 (Monday, January 5th 2009)
- MySQL queries for article summaries part 1 of 2 (Sunday, January 4th 2009)
- 2008 Summary of Posts (Saturday, January 3rd 2009)
- 2008 / 2009 overview (Friday, January 2nd 2009)
Subscribe to RSS Feed / Email / Bookmark / Share
Use the buttons below to subscribe to my RSS feed to be notified next time something is posted, share this post with others, or subscribe by email and have my posts sent in a daily email.
Posts are made using the following schedule (although it may vary some weeks): Mondays & Fridays = PHP; Tuesdays & Saturdays = MySQL; Wednesdays & Sundays = Javascript/jQuery; Thursdays = HTML/CSS.
