Jump to content

Recommended Posts

Posted

I uploaded previously some PNG images to my page, into Images field.

However, after some wrok on page (without touching this field and/or page), I see this:

Warning: imagepng() [function.imagepng]: gd-png: fatal libpng error: zlib failed to initialize compressor -- stream error in /_Adam/server/-client-/wire/core/ImageSizer.php on line 163

Warning: imagepng() [function.imagepng]: gd-png error: setjmp returns error condition in /_Adam/server/-client-/wire/core/ImageSizer.php on line 163

Warning: imagepng() [function.imagepng]: gd-png: fatal libpng error: zlib failed to initialize compressor -- stream error in /_Adam/server/-client-/wire/core/ImageSizer.php on line 163

Warning: imagepng() [function.imagepng]: gd-png error: setjmp returns error condition in /_Adam/server/-client-/wire/core/ImageSizer.php on line 163

Warning: imagepng() [function.imagepng]: gd-png: fatal libpng error: zlib failed to initialize compressor -- stream error in /_Adam/server/-client-/wire/core/ImageSizer.php on line 163

Warning: imagepng() [function.imagepng]: gd-png error: setjmp returns error condition in /_Adam/server/-client-/wire/core/ImageSizer.php on line 163

And the images are deleted. WTF?

Posted

Ha, I got this one.

Code is on this line:

case 'png': imagepng($thumb2, $dest, floor($this->quality / 10)); break;

Obiously, PNG has quality setting '0..9' (http://uk.php.net/manual/en/function.imagepng.php#refsect1-function.imagepng-parameters). This mostly work, but when I set quality to 100 (maximum JPEG quality), floor return 10, which is out of bounds (thus receiving error while creating new PNG image).

Other than that, I believe that this floor(..) calculation is wrong; It seems that PNG quality is set from 0 to 9, but 0 being no compression, thus highest quality – that means, that quality '9' isn't highest (as the calculation suggests), but in fact, lowest.

Posted

Adam, good find. I've updated the code to this and am committing it now:

<?php
// convert 1-100 (worst-best) scale to 0-9 (best-worst) scale for PNG
$quality = round(abs(($this->quality - 100) / 11.111111));
imagepng($thumb2, $dest, $quality);

I also tested the quality settings manually by inserting the quality number in there. The problem is that [at least on my dev server] there is no visible difference in quality or filesize between specifying 0 and 9 to the imagepng() function. Do you find this to be the case there too?

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...