This question already has an answer here:
这个问题已经有了答案:
- Can I access ImageMagick API with Python? 3 answers
- 我能用Python访问ImageMagick API吗?3答案
I want to define a function that "call" imagemagick to convert an image.
我想定义一个函数“调用”imagemagick来转换图像。
def convert(filein,fileout):
#imagemagick>convert filein fileout
How can I call and use imagemagick with Python?
如何在Python中调用和使用imagemagick ?
I'm running on a linux system, imagemagick is installed, and I'm not using PIL.module because it doesn't handle PPM[p3].
我正在一个linux系统上运行,安装了imagemagick,而且我没有使用PIL。因为它不处理PPM[p3]。
4 个解决方案
#1
7
Either use one of the shell interfaces of Python (os.system, subprocess.Popen) to call the imagemagick binary, or try out PythonMagick.
或者使用Python (os)的shell接口之一。调用imagemagick二进制,或者尝试使用PythonMagick。
#2
15
Disclaimer: I am the author of Wand.
免责声明:我是魔杖的作者。
You can easily do that using Wand, a simple binding of ImageMagick for Python. For example, the following code converts a PNG image to a JPEG image:
您可以使用Wand轻松做到这一点,这是Python的一个简单的ImageMagick绑定。例如,以下代码将PNG图像转换为JPEG图像:
from wand.image import Image
with Image(filename='in.png') as img:
img.format = 'jpeg'
img.save(filename='out.jpg')
See this tutorial as well.
也请参阅本教程。
#3
6
I would suggest u use subprocess it is safer
我建议你使用子过程,这样更安全。
import subprocess
params = ['convert', 'src_file', 'result_file']
subprocess.check_call(params)
#4
3
I have not used image magic but you could use os.system to call a shell command:
我没有使用图像魔术,但你可以使用操作系统。系统调用shell命令:
import os
os.system('imagemagick-converting-command filein fileout')
I suggest you go with PythonMagic as Creshal said. It is provided by ImageMagic and thus must be one of the best port available for python.
我建议你按照克雷沙尔的话去做。它由ImageMagic提供,因此必须是python可用的最佳端口之一。
#1
7
Either use one of the shell interfaces of Python (os.system, subprocess.Popen) to call the imagemagick binary, or try out PythonMagick.
或者使用Python (os)的shell接口之一。调用imagemagick二进制,或者尝试使用PythonMagick。
#2
15
Disclaimer: I am the author of Wand.
免责声明:我是魔杖的作者。
You can easily do that using Wand, a simple binding of ImageMagick for Python. For example, the following code converts a PNG image to a JPEG image:
您可以使用Wand轻松做到这一点,这是Python的一个简单的ImageMagick绑定。例如,以下代码将PNG图像转换为JPEG图像:
from wand.image import Image
with Image(filename='in.png') as img:
img.format = 'jpeg'
img.save(filename='out.jpg')
See this tutorial as well.
也请参阅本教程。
#3
6
I would suggest u use subprocess it is safer
我建议你使用子过程,这样更安全。
import subprocess
params = ['convert', 'src_file', 'result_file']
subprocess.check_call(params)
#4
3
I have not used image magic but you could use os.system to call a shell command:
我没有使用图像魔术,但你可以使用操作系统。系统调用shell命令:
import os
os.system('imagemagick-converting-command filein fileout')
I suggest you go with PythonMagic as Creshal said. It is provided by ImageMagic and thus must be one of the best port available for python.
我建议你按照克雷沙尔的话去做。它由ImageMagic提供,因此必须是python可用的最佳端口之一。