使用Imagick重新调整大小的PNG是黑色的... PHP中缺少的步骤是什么?

When I use Imagick in PHP to resize PNG images, the output images are black. This is not the case when I resize JPGs; the PHP procedure (provided below) works perfectly for JPGs, so I suspect there's a missing step when processing PNG files.

I've first tested the conversion using ImageMagick on my local computer using this command:

convert x.png -resize 528 -filter Lanczos x-resized.png

...and it works; the resulting PNG file displays and is resized appropriately.

However, when I attempt to do the same on my server (both localhost and live), the result is a black image.

The PHP code I'm using is:

$source = "x.png" // I provide the complete path in my routine, etc.
$destination = "x-resized.png" // likewise.

$im = new Imagick();
$im->readImage($source);
$im->setImageFormat("png");
$im->resizeImage(528, null, Imagick::FILTER_LANCZOS, 1);
$im->writeImage($destination);
$im->clear();

What am I doing incorrectly?

douyi1966
douyi1966 此外,如果其他图像可以正常工作,也可以发布不起作用的示例源图像。
接近 5 年之前 回复
dongxian6653
dongxian6653 出了点问题,我不认为这是你的代码。你是怎么安装Imagick和ImageMagick的?
接近 5 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐