使用Imagick将彩色PDF转换为适合传真的灰度PDF

3

我正在尝试将彩色PDF转换为适合传真的PDF(不使用过多墨水),Twilio处理方式非常好。我相信用Imagick也可以做到。我的主要动机是在我的服务器端使用Imagick进行转换,这样我的输入和输出就不会完全不同于Twilio的转换。

我尝试了这些方法,但它们似乎与Twilio的不同:

$img->quantizeImage(255, Imagick::COLORSPACE_GRAY, 1, TRUE, FALSE);
$img->writeImage('output.png');

// and 
$img->quantizeImage(1, Imagick::COLORSPACE_GRAY, 1, TRUE, FALSE);

以上代码片段实现了完全的颜色转换。


让我向您展示Twilio是如何做到的:

原始PDF:

enter image description here

Twilio转换后的PDF:

enter image description here

以及Twilio转换后的PDF的缩放版本和实心背景颜色的图案:

enter image description here

enter image description here


我相信 Imagick 对象的方法应该是:http://php.net/manual/en/imagick.orderedposterizeimage.php .. http://php.net/manual/en/imagick.transformimagecolorspace.php - IncredibleHat
1个回答

2

您没有发布实际的PDF文件,而是PNG图像。所以我使用了它。如果这不起作用,请发布您的PDF链接。

在Imagemagick中,您可以添加一个抖动模式。我假设在Imagick中有等效的命令。以下是Imagemagick命令。

convert l9IYF.png -colorspace gray -ordered-dither o3x3 tmp.png

enter image description here

convert l9IYF.png -colorspace gray -ordered-dither h6x6a tmp2.png

enter image description here

请参考https://www.imagemagick.org/Usage/quantize/#ordered-ditherhttp://us3.php.net/manual/en/imagick.orderedposterizeimage.php


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接