Menu

png compression error

Help
2014-02-04
2014-02-04
  • Flavio Avelar Cambraia

    I get the following error when dealing with a png file:
    Line -> 39
    File -> C:\EasyPHP\www\projeto\config\wide_image\Mapper\PNG.php
    Description -> imagepng(): gd-png error: compression level must be 0 through 9.

    My script works fine with jpg and gif. I am doing this:
    $image = WideImage::load($filein);
    $back_color = $image->allocateColor(255, 0, 0);
    $resized = $image->resize($max_width, $max_height, 'inside')->resizeCanvas($max_width, $max_height, 'center', 'center', $back_color);
    $resized->saveToFile($imagens_dir."/".$fileout,90);
    $resized->destroy();

    Thanks,
    Flavio

     
  • Flavio Avelar Cambraia

    Ops, I just found my error.
    saveToFile($imagens_dir."/".$fileout,90);
    I have to test the file (jpg or png) and set compression before saving.

     
  • Gasper Kozak

    Gasper Kozak - 2014-02-04

    Flavio,

    PNG doesn't have quality, only compression.

    Quote from WideImage doc:

    Note: don’t be confused if you notice that the compression level parameter of imagepng() has been incorrectly named “quality” in the PHP manual. PNG format has no quality the way JPEG has it (smaller file size ~= uglier image). It’s a lossless image format, so no detail is lost (= the quality remains the same) regardless of the compression level.

     

Log in to post a comment.