Python bindings for ImageMagick’s MagickWand API
I’ve been spending some of my spare time recently putting together some Python bindings for ImageMagick’s MagickWand API. While most bindings I’ve seen just look like generated ctypes code from C header files, these bindings are more object-oriented, completely hiding the MagickWand methods. While this is still in the early stages, it’s workable in a way which I hope is expected and unsurprising:
from pythonmagick.image import Image
from pythonmagick.color import BLUE
i = Image('foo.jpg')
i.format = 'PNG'
i.rotate(45, BLUE)
i.save('flip.png')
The above reads in a JPEG image, reformats to PNG and rotates by 45 degrees with a background colour of blue. The image is then saved to a new file.
This may look a lot like PIL code, so why not use it instead of ImageMagick? ImageMagick covers a much wider range of image formats than PIL, and supports better algorithms for image resizing.
Check out the bindings by installing them with easy_install:
easy_install http://svn2.assembla.com/svn/pythonmagickwand/trunk/
On a side note, I’m quite impressed with Assembla, the site which I’m using for my SVN and Trac repo. It’s about as good as something I would deploy myself, but with much less hassle. Honestly, these days there’s less and less reason for me to spend hours setting up stuff myself, and that’s a great thing.
This entry was posted on Friday, March 14th, 2008 at 12:23 pm and is filed under python. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
luispedro Says:
April 17th, 2008 at 3:50 pm
This looks good.
What is the License on this code?
Ian Stevens Says:
April 17th, 2008 at 11:17 pm
I haven’t really thought about it luispedro. I’ll have to get back to you on that.
Ben Says:
September 29th, 2008 at 3:56 am
from pythonmagickwand.image import Image
from pythonmagickwand.color import BLUE
i = Image(’test.jpg’)
i.format = ‘PNG’
i.rotate(45, BLUE)
i.save(’flip.png’)
looks like it’s renamed.