![](/img/trans.png)
[英]How can I save a figure in tiff with 600 dpi with compression using matplotlib?
[英]convert PDF into TIFF with 600dpi and jpg 96 dpi
我想使用 ImageMagick 从 Python 脚本将 pdf 转换为 600 dpi 的 tiff 和 96 dpi 的 jpg。
我使用 (imagemagick) 命令行完成了这项任务,但我想在 python 中使用 Imagemagick 将 pdf 转换为 tiff 和 jpg,
你能帮我吗......
首先,您必须在 imagemagick 库周围加载一个包装器
使用PythonMagick :
from PythonMagick import Image
或使用pgmagick :
from pgmagick import Image
然后,独立于您加载的库,以下代码将转换和调整图像大小
img = Image()
img.density('600') # you have to set this here if the initial dpi are > 72
img.read('test.pdf') # the pdf is rendered at 600 dpi
img.write('test.tif')
img.density('96') # this has to be lower than the first dpi value (it was 600)
# img.resize('100x100') # size in px, just in case you need it
img.write('test.jpg')
# ... same code as with pythonmagick
可以使用subprocess 模块执行 imagemagick 命令
import subprocess
params = ['convert', "Options", 'pdf_file', 'thumb.jpg']
subprocess.check_call(params)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.