我可以用Python访问ImageMagick API吗?
我需要使用,因为PIL没有足够的图像功能,我正在寻找。但是,我想使用Python python绑定(PythonMagick)自2009年以来一直没有更新过。我唯一能找到的就是我可以用Python访问ImageMagick API吗?,python,imagemagick,image-manipulation,ctypes,Python,Imagemagick,Image Manipulation,Ctypes,我需要使用,因为PIL没有足够的图像功能,我正在寻找。但是,我想使用Python python绑定(PythonMagick)自2009年以来一直没有更新过。我唯一能找到的就是os.system调用命令行界面,但这看起来很笨拙 是否有任何方法可以使用ctypes和某种转换直接访问API? 作为最后一种手段,是否还有其他库拥有大量图像编辑工具,如我看过的ImageMagick?我建议使用(解释如下) 我正在寻找与ImageMagick库的适当绑定,这将: 工作错误/无问题 定期维护和更新 允许漂
os.system
调用命令行界面,但这看起来很笨拙
是否有任何方法可以使用ctypes
和某种转换直接访问API?
作为最后一种手段,是否还有其他库拥有大量图像编辑工具,如我看过的ImageMagick?我建议使用(解释如下)
我正在寻找与ImageMagick库的适当绑定,这将:
- 工作错误/无问题
- 定期维护和更新
- 允许漂亮的目标Python
- 图形美术
- PythonMagick-第一个实现
- PythonMagickWand/Achim Domma-第一个Wand-a CDLL实现
- PythonMagickWand/Ian Stevens
- MagickFoo-包含在python magickwand中
- Wand/Hong Minhee-最新项目
因此,它已经是一个易于维护的简化接口。我发现ImageMagick没有很好的Python绑定,所以为了在Python程序中使用ImageMagick,我必须使用
子流程
模块重定向输入/输出
例如,假设我们需要将PDF文件转换为TIF:
path = "/path/to/some.pdf"
cmd = ["convert", "-monochrome", "-compress", "lzw", path, "tif:-"]
fconvert = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = fconvert.communicate()
assert fconvert.returncode == 0, stderr
# now stdout is TIF image. let's load it with OpenCV
filebytes = numpy.asarray(bytearray(stdout), dtype=numpy.uint8)
image = cv2.imdecode(filebytes, cv2.IMREAD_GRAYSCALE)
在这里,我使用了
tif:-
告诉ImageMagick的命令行实用程序,我希望将tif图像作为标准输出流。以类似的方式,您可以通过指定-
作为输入文件名来告诉它使用stdin stream作为输入。对于我来说,以下命令可以从字母“p”的文本创建图像:
我远离匮乏的主要原因是:
import subprocess
cmd = '/usr/local/bin/convert -size 30x40 xc:white -fill white -fill black -font Arial -pointsize 40 -gravity South -draw "text 0,0 \'P\'" /Users/fred/desktop/draw_text2.gif'
subprocess.call(cmd, shell=True)