52

我有以下内容:

ghostscript-fonts-5.50-24
ImageMagick-6.7.2-1
ghostscript-9.02-1

我用它为每个页面创建一系列 JPG,使用:

convert -density 175 -colorspace sRGB test.pdf -resize 50% -quality 95 test.jpg

当我在我的 Windows 机器上运行它时,一切似乎都可以正常工作,但在我们的 linux 服务器上,我们遇到了黑色背景问题。

生成的 JPG 具有黑色背景,使图像无法读取,我缺少什么或者我应该做些什么来纠正这个问题?

几天来我一直在谷歌上,但每个建议似乎都对我不起作用。

非常感谢任何帮助,在此先感谢:)

编辑

只是在转换其中一个产生黑色背景的 PDF 时注意到了这个输出:

**** Warning: Fonts with Subtype = /TrueType should be embedded.
             The following fonts were not embedded:
                    Arial
                    Arial,Bold
                    Arial,BoldItalic
**** This file had errors that were repaired or ignored.
**** The file was produced by:
**** >>>> Microsoft« Word 2010 <<<<
**** Please notify the author of the software that produced this
**** file that it does not conform to Adobe's published PDF
**** specification.

这似乎是相关的,但由于我们无法控制 PDF 的生成方式,我们需要某种方法来修复此服务器端。

再次感谢

4

3 回答 3

94

今天跑到这个,发现这个:

https://www.imagemagick.org/discourse-server/viewtopic.php?t=20234

基于此,这些都应该有效:

  • -flatten
  • -alpha flatten
  • -alpha remove

我目前正在为我的具体案例使用以下内容,效果很好:

convert -thumbnail "1280x800>" -density 300 -background white -alpha remove in.pdf out.jpg
于 2013-04-30T06:22:06.420 回答
11

解决此问题的简单方法是使用支持透明度的图像格式,例如 png。

所以:

convert -density 175 -colorspace sRGB test.pdf -resize 50% -quality 95 test.png

问题解决了 :)

于 2012-08-21T11:22:06.313 回答
3

如果您想要高质量的结果,请使用以下命令:

convert -density 700 input.pdf -resize 25% -append  -quality 98 -alpha remove output.jpg

对于 windows 用户,使用magick代替convert

于 2019-10-22T04:46:47.313 回答