图像魔术师和PNG上传

时间:2016-07-11 18:18:46

标签: php imagemagick

尝试上传png时,我遇到了GD问题。我得到的错误是

Warning: imagepng(): gd-png error: compression level must be 0 through 9... on line 2474
php_image_magician.php中第2474行的

是png

的情况
            case '.png':
    // *** Scale quality from 0-100 to 0-9
    $scaleQuality = round(($imageQuality/100) * 9);

    // *** Invert qualit setting as 0 is best, not 9
    $invertScaleQuality = 9 - $scaleQuality;

    $this->checkInterlaceImage($this->isInterlace);
    if (imagetypes() & IMG_PNG) {
       imagepng($this->imageResized, $savePath, $invertScaleQuality);
    } else { $error = 'png'; }
            break;

,更具体地说,这个

imagepng($this->imageResized, $savePath, $invertScaleQuality);

上传jpg张图片时没有错误..

这是我的上传文件中的问题

  $magicianObj = new imageLib($filepath);
  $magicianObj->resizeImage(300, 300);
  $magicianObj->saveImage($folderName . 'thumb/' . $filename, 300);    

当我调整它们的大小时,

1 个答案:

答案 0 :(得分:1)

Rereading your post again it looks like you are having problems with all png files. What value are you using for the png image quality as this line recalculates it:

$scaleQuality = round(($imageQuality/100) * 9);

If you use an image quality in you code of 9 it will be changed to 0.81

Then again this line

$invertScaleQuality = 9 - $scaleQuality;

would convert the 0.81 to 8.19

Anyway I guess the problem is in the php file and not GD. I would echo some of the code out to see what values are being passed to the GD code.

You could also try hardcoding $invertScaleQuality to a value between 0 and 9 to see if that works.