如何在python子进程中指定图像输出的维度?

时间:2017-05-25 05:12:08

标签: python imagemagick subprocess imagemagick-convert

我想将pdf文件转换为图片。我想指定图像的输出维度。我该怎么做?

import subprocess
#I want to pass output dimension as parameter. How do I do that 
params = ['convert','./data/in.pdf','thumnails.jpg']
subprocess.check_call(params) 

1 个答案:

答案 0 :(得分:1)

虽然我并不真正使用image-magickconvert命令行命令。但我做了一些研究,发现你可以使用-resize参数来调整图像大小。您可以参考herehere以及here了解详情。要将其合并到从subprocess开始运行,您可以执行以下操作:

import subprocess
#I want to pass output dimension as parameter. How do I do that 
params = ['convert','./data/in.pdf','-resize', '100x100', 'thumnails.jpg'] # replace 100x100 with your width x height 
subprocess.check_call(params) 

或者,您可以尝试使用-density参数:

params = ['convert', '-density', '100x100', './data/in.pdf', 'thumnails.jpg'] # replace 100x100 with your width x height