我想使用将PDF转换为PNG图像convert
。图像必须具有?x1080的比例,以适合1920x1080的比例,并具有最佳的质量。
这是我可以与convert一起使用的许多选项:https : //imagemagick.org/script/command-line-options.php#append
convert my.pdf -geometry 1920x1080 -size 1920x1080 -density 1920x1080 my_resized_pdf.png
命令的结果为我提供了具有良好几何形状(763x1080)的图像,但是我不想得到低质量的图像。
convert my.pdf -size 1920x1080 -density 1920x1080 my_resized_pdf.png
结果的质量恰好是我想要的,但分辨率不是1920x1080的比率,而是842x595。它不能完全适合1920x1080比例的高度。
Is it possible to get PNG images with a ?x1080 ratio and with a 100% quality from a PDF ? Or is 842x595 the biggest ratio to get a 100% quality image ? Should i set a DPI option to convert
?
This involves some trial & error and in the end, it's debatable which result you might consider to be the "best result". So allow me to just give some generic advice:
use the -flatten
option to get rid of transparent background. The transparency makes it hard to judge actual quality of the result. If you need the transparency in the final image, you can remove -flatten
once you're sure of the quality.
use something like -density 300
to get a high DPI result. The main issue with convert
is that it uses a very low density by default (72 DPI). This parameter has to be specified before the input file.
downscaling a high DPI image might cause additional blur, so perhaps calculating the correct DPI value to achieve the desired resolution is the way to go:
$ convert -density 100 file.pdf -flatten file100.png
$ file file100.png
file100.png: PNG image data, 827 x 1169, 8-bit colormap, non-interlaced
$ echo $((1080*10000/1169))
9238
$ convert -density 92.38 file.pdf -flatten file9238.png
$ file file9238.png
file9238.png: PNG image data, 764 x 1080, 8-bit colormap, non-interlaced
I'm not sure if there is a way to have convert
determine "ideal" DPI value by itself.
If you take this question to the ImageMagick IRC channel or forum, I'm sure you'd get some more advice. It helps if you provide the link to the PDF file you're working with. ;)
您还可以通过其他方式提高质量,例如通过修剪掉空白边框。如果页面的一半是白色,则会损失很多分辨率。甚至有重新包装PDF文本以充分利用可用屏幕空间的解决方案(例如k2pdfopt
)。
最后,也尝试其他程序。这是一个见解,但我更喜欢直接使用Inkscape或GhostScript。ImageMagick具有“粘合在一起”的字符,Inkscape具有更平衡的结果,并且GhostScript允许您渲染无模糊的纯像素图像(如果您喜欢的话-pngalpha
用于模糊版本,实际上与相同convert
)。
ImageMagick:
墨迹:
GhostScript:
gs -r92.38 -sDEVICE=png48 -sOutputFile=ghostscript.png file.pdf
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句