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:
My original code looked like this:
and I simply changed the function name and filename like this:
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:
Note that 0 means no compression and 9 means the highest compression possible i.e. the scale is reversed when compared with JPEG images.
0 comments:
Post a Comment