ANSI2Img: Convert ANSI to Bitmaps


Comments

Id like to say thanks for this too. Very nice work, i learnt a lot looking at your source. I thought id post a few lines on how to get this working quickly, if you're like me and spend ages trying to understand code (i didn't see any basic tutorial) :)

You'll need to adapt this slightly to your needs and i wont guarantee it works...

from cStringIO import StringIO
import renderconsole
 
# your file
data = open('art.ansi').read()
# or your string
data = "Û²±° ".decode('utf-8')
 
# create a memory file, i wanted to display "dynamically" on the web with no files written to disk
png = StringIO()
 
font = renderconsole.DefaultFont()
framebuffer = renderconsole.Framebuffer(80, 25, growable=True)
term = renderconsole.ANSITerminalEmulator(framebuffer)
screen = renderconsole.PNGWriter(framebuffer, font, stream=png)
 
term.write(data)
screen.render()
 
# get data in mem file, this is the image, with the correct http headers it will display in a browser
png.getvalue()

You can just put the renderconsole folder in with your script to allow python to import, or you can install fully. You need the Python Imaging Library (PIL) as well of course.

Thank you very much for this! I was in a hurry (usually am), and didn't post any example code for this — after all, the initial idea was for some friends to use it on my web page.

This is pretty self-explanatory, though I should definitely make default initialisation easier in simple cases like this (having to construct all those objects separately is more Java-esque than Pythonic).

Thanks a lot for coding this. It works great :-)

Thank you!