使用ImageMagick和python.(在Linux系统上)

Alp*_*gut 13 python linux imagemagick

我想定义一个"调用"imagemagick来转换图像的函数.

def convert(filein,fileout):
#imagemagick>convert filein fileout
Run Code Online (Sandbox Code Playgroud)

如何在Python中调用和使用imagemagick?

我正在linux系统上运行,安装了imagemagick,我没有使用PIL.module,因为它不处理PPM [p3].

min*_*hee 15

免责声明:我是魔杖的作者.

您可以使用Wand轻松完成此操作,Wand是ImageMagick for Python的简单绑定.例如,以下代码将PNG图像转换为JPEG图像:

from wand.image import Image

with Image(filename='in.png') as img:
    img.format = 'jpeg'
    img.save(filename='out.jpg')
Run Code Online (Sandbox Code Playgroud)

也请参阅本教程.


Cre*_*hal 7

使用Python的一个shell接口(os.system,subprocess.Popen)来调用imagemagick二进制文件,或者尝试使用PythonMagick.


Rak*_*esh 6

我建议你使用subprocess它更安全

import subprocess
params = ['convert', 'src_file', 'result_file']
subprocess.check_call(params)
Run Code Online (Sandbox Code Playgroud)