Python 使用600dpi和jpg 96 dpi将PDF转换为TIFF

Python 使用600dpi和jpg 96 dpi将PDF转换为TIFF,python,linux,imagemagick,Python,Linux,Imagemagick,我想使用ImageMagick从Python脚本将pdf转换为600 dpi的tiff和96 dpi的jpg 我使用(imagemagick)命令行完成了这项任务,但我想使用python中的imagemagick将pdf转换为tiff和jpg 你能帮我一下吗?…你可以使用来执行imagemagick命令 import subprocess params = ['convert', "Options", 'pdf_file', 'thumb.jpg'] subprocess.check_call(

我想使用ImageMagick从Python脚本将pdf转换为600 dpi的tiff和96 dpi的jpg

我使用(imagemagick)命令行完成了这项任务,但我想使用python中的imagemagick将pdf转换为tiff和jpg

你能帮我一下吗?…

你可以使用来执行imagemagick命令

import subprocess
params = ['convert', "Options", 'pdf_file', 'thumb.jpg']
subprocess.check_call(params)
您可以使用执行imagemagick命令

import subprocess
params = ['convert', "Options", 'pdf_file', 'thumb.jpg']
subprocess.check_call(params)

首先,您必须加载imagemagick库的包装器

使用:

或使用:

然后,独立于您加载的库,以下代码将转换图像并调整其大小

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 

首先,您必须加载imagemagick库的包装器

使用:

或使用:

然后,独立于您加载的库,以下代码将转换图像并调整其大小

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 

但我只想使用imagemagick将pdf转换为tiff和jpg,而不是使用imagemagick的python接口(pythonmagick)…所以我认为Rakesh的答案就是您想要的:)我试图添加pythonmagick库,但它不可用。有人能得到它吗?@Amadeus:PythonMagick是一个古老的库,所以我添加了一个更新的替代品PgMagick,它有更好的文档记录,应该更容易安装。希望能有帮助。@furins我找到了另一个解决方案,但我会标记你的答案以备将来使用。谢谢你的回复!但我只想使用imagemagick将pdf转换为tiff和jpg,而不是使用imagemagick的python接口(pythonmagick)…所以我认为Rakesh的答案就是您想要的:)我试图添加pythonmagick库,但它不可用。有人能得到它吗?@Amadeus:PythonMagick是一个古老的库,所以我添加了一个更新的替代品PgMagick,它有更好的文档记录,应该更容易安装。希望能有帮助。@furins我找到了另一个解决方案,但我会标记你的答案以备将来使用。谢谢你的回复!