在Linux系统上使用ImageMagick和Python
我想定义一个函数,用来“调用”imagemagick来转换图片。
def convert(filein,fileout):
#imagemagick>convert filein fileout
我该如何在Python中调用和使用imagemagick呢?
我是在一个Linux系统上运行,imagemagick已经安装好了,而且我不使用PIL模块,因为它不支持PPM[p3]格式。
4 个回答
6
我建议你使用subprocess,这样更安全。
import subprocess
params = ['convert', 'src_file', 'result_file']
subprocess.check_call(params)
8
你可以用Python的一个命令行接口,比如os.system或者subprocess.Popen,来调用imagemagick这个程序,或者试试PythonMagick这个库。