GraphicsMagic无法识别PDF的背景透明度

GM无法识别PDF的背景透明度,使用“gm convert”创建的PNG获取白色背景,而相同的PDF通过IM转换为具有透明背景的PNG .

$convert -verbose /var/tmp/abc.pdf /var/tmp/abc.png
/var/tmp/magick-16370Tq7WYv5U54Pa1 PNG 288x720 288x720+0+0 8-bit sRGB 20.7KB 0.000u 0:00.009
/var/tmp/abc.pdf PDF 288x720 288x720+0+0 16-bit sRGB 20.7KB 0.000u 0:00.000
/var/tmp/abc.pdf=>/var/tmp/abc.png PDF 288x720 288x720+0+0 8-bit sRGB 17c 16.6KB 0.010u 0:00.009
[ghostscript library] -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" "-sOutputFile=/var/tmp/magick-16370Tq7WYv5U54Pa%d" "-f/var/tmp/magick-16370CVWmPbzBmjpF" "-f/var/tmp/magick-16370khy6Y-G3TgtO"
$gm convert -verbose /var/tmp/abc.pdf /var/tmp/abc.png
gm convert: "gs" "-q" "-dBATCH" "-dMaxBitmap=50000000" "-dNOPAUSE" "-sDEVICE=pnmraw" "-dTextAlphaBits=4" "-dGraphicsAlphaBits=4" "-r72x72" "-sOutputFile=/var/folders/6d/n_hv45rs1jv17nxwfjwj776cspn_3c/T/gmoCp6rG" "--" "/var/folders/6d/n_hv45rs1jv17nxwfjwj776cspn_3c/T/gmBEgWnK" "-c" "quit".
/var/tmp/abc.pdf PDF 288x720+0+0 DirectClass 8-bit 607.6K 0.000u 0:01
/var/tmp/abc.pdf=>/var/tmp/abc.png PNG 288x720+0+0 DirectClass 8-bit 0.000u 0:01
Upon further investigation, it seems "identify" from IM can correctly identify background in PDF but "gm identify" from GM cannot.
$identify -verbose abc.pdf
Image: abc.pdf
Format: PDF (Portable Document Format)
Type: Bilevel
Colorspace: Gray
Depth: 16/4-bit
Channel depth:
gray: 1-bit
alpha: 4-bit
Alpha: graya(255,0) #FFFFFFFFFFFF0000
Colors: 16
Background color: graya(255,1)
Transparent color: graya(0,0)
Version: ImageMagick 6.8.9-1 Q16 x86_64 2014-07-01 http://www.imagemagick.org
$gm identify -verbose abc.pdf
gm identify: "gs" "-q" "-dBATCH" "-dMaxBitmap=50000000" "-dNOPAUSE" "-sDEVICE=pnmraw" "-dTextAlphaBits=4" "-dGraphicsAlphaBits=4" "-r72x72" "-sOutputFile=/var/folders/6d/n_hv45rs1jv17nxwfjwj776cspn_3c/T/gmzhBEIk" "--" "/var/folders/6d/n_hv45rs1jv17nxwfjwj776cspn_3c/T/gmAPm2Po" "-c" "quit".
Image: abc.pdf
Format: PDF (Portable Document Format)
Type: grayscale
Depth: 4 bits-per-pixel component
Channel Depths:
Gray: 4 bits
Background Color: white
Comment: Image generated by GPL Ghostscript (device=pnmraw)
Signature: 215f1c08ec575526ce398d193c4df22faaea100c10255e0db747641bdaaeac49
Tainted: False

回答(2)

2 years ago

你的(ImageMagick) convert 和你的(GraphicsMagick) gm convert 命令产生不同输出的原因是:

  • 两个实用程序都能够直接处理PDF输入文件,两者都只能处理评估者图像格式 .

  • 为了处理PDF输入文件,两个实用程序都采用'delegate'程序:在这两种情况下都是Ghostscript( CAN 处理PDF输入文件) .

  • 然而,两个实用程序都使用 different 'delegate command lines'(可以在引用的 -verbose 命令行输出中直接看到:

一世 . convert 用作其Ghostscript输出设备 pngalpha .

II . gm convert 用作其Ghostscript输出设备 pnmraw .

  • 两个实用程序然后将其委托命令的输出处理为最终(栅格)格式文件 .

问题是:栅格格式'pnmraw'不支持透明度(alpha通道),但'pngalpha'支持透明度 . 因此,首先将PDF输入转换为pnmraw的实用程序已丢失透明页面背景并将其替换为(不透明)白色背景 .

Unless you modify your GraphicsMagick setup to make it use pngalpha in its delegate command (the same as ImageMagick uses) your gm convert will not show transparent background.

2 years ago

只是想添加到Kurt Pfeifle答案,因为它向我指出了这个解决方案 . 他所引用的配置可在 delegates.mgk 文件中找到(graphicsmagick / 1.3.19_1 / lib / GraphicsMagick / config) .

对我来说,问题是这一行:

<!-- Read color Postscript, EPS, and PDF  -->
<delegate decode="gs-color" stealth="True" command='"gs" -q -dBATCH -dMaxBitmap=50000000 -dNOPAUSE -sDEVICE=ppmraw -dTextAlphaBits=%u -dGraphicsAlphaBits=%u -r%s %s "-sOutputFile=%s" -- "%s" -c quit' />

我改成了:

<delegate decode="gs-color+alpha" stealth="True" command='"gs" -q -dBATCH -dMaxBitmap=50000000 -dNOPAUSE -sDEVICE=pngalpha -dTextAlphaBits=%u -dGraphicsAlphaBits=%u -r%s %s "-sOutputFile=%s" -- "%s" -c quit' />

我的朋友出来透明背景!