Using Imagemagick without creating files?

I work in Python to create images from text. I've already been back and forth with PIL, and frankly, its fonts and alignment options require a lot of work.

I can sub-process Imagemagick and it works great, except that it seems like you always need to write the file to disk. I would like an image creation subprocess and just get the data returned by Python, storing everything in memory.

I looked at some of the alleged Python wrappers for ImageMagick, but they are all hopelessly outdated or not documented at all. Even widespread search on SO does not see to clearly indicate the defacto way to use ImageMagic with Python. Therefore, I think that switching to a subprocess is the best way to move forward.

+4
source share
2 answers

convert , and the rest of ImageMagick commands can output image data to stdout if you specify format:- as the output file. You can write this output in Python using the subprocess module.

For instance:

 cmd = ["convert", "test.bmp", "jpg:-"] output_stream = subprocess.Popen(cmd, stdout=subprocess.PIPE).stdout 
+7
source

For ImageMagick, it would be much more than pipelined data, but there are several Pango-based solutions. I used pango and pygtk a while ago, and I'm sure you could develop a mute gtk or gdk application to render text in pixbuf.

A simpler solution might be to use python cairo bindings.

Pango works at a fairly low level, so simple things can be much more complicated, but the playback quality is hard to beat, and it gives you a lot of fine-grained control over the layout.

0
source

All Articles