• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
The Electric Toolbox Blog

The Electric Toolbox Blog

Linux, Apache, Nginx, MySQL, Javascript and PHP articles

  • Applications
  • FCKEditor
  • Apache
  • Windows
  • Contact Us
Home / PHP fatal libpng error: zlib error

PHP fatal libpng error: zlib error

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 and filename like this:

ImagePNG($image, 'filename.png, 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. The resulting code looks like this, where there is no compression:

ImagePNG($image, 'filename.png, 0);

Note that 0 means no compression and 9 means the highest compression possible i.e. the scale is reversed when compared with JPEG images.

Check Out These Related posts:

  1. Generate thumbnails with PHP
  2. NordVPN vs IPVanish
  3. What Is a VPN?
  4. Extract inline image attachments from an email with PHP

Filed Under: PHP

Primary Sidebar

Categories

  • Apache
  • Applications
  • Article
  • Case Studies
  • Email Servers
  • FCKEditor
  • HTML And CSS
  • Javascript
  • Linux/Unix/BSD
  • Microsoft SQL Server
  • Miscellaneous Postings
  • MySql
  • Networking
  • Nginx Web Server
  • Offsite Articles
  • OSX
  • PHP
  • Quick Tips
  • RFC – Request for Comments
  • SilverStripe
  • VMWare
  • VPN
  • Windows
  • WordPress

Recent Posts

  • Vim Show Line Numbers
  • Add User To Group Linux
  • Chmod 777 Tutorial
  • How to Copy Directory Linux
  • Linux create user

Copyright © 2021. ElectricToolBox. All Rights Reserved.

  • Contact Us
  • Copyright Info
  • Privacy Policy
  • Sitemap