BedroomLANTilde~A: Alexios' HomepageSearch |
![]() |
||
ANSI2Img: Convert ANSI to Bitmaps
Posted February 28th, 2009 by alexios
This small Python program converts ANSI art to raster images. It simulates a PC's text mode using different VGA soft fonts (or EGA, or the CGA ROM font) and renders colourful BBS graphics, affectionately known as ANSI (after the ANSI.SYS MS-DOS driver that rendered them back in the day). So-called ‘ANSI’ graphics are text files in one of the IBM PC extended ‘ASCII’ encodings. The files include terminal directives for the MS-DOS terminal driver ANSI.SYS, which implements a small subset of the ANSI X.364 standard for Control Sequences for Video Terminals. With the special characters in the various IBM PC character sets, box-drawing and crude graphics were feasible. Using ANSI, these graphics could also be coloured and even repositioned for simple animations. Such files were commonly used on Bulletin Board Systems (BBS) and other similar software and, despite (or perhaps because) of the limitations of the format, eventually developed into an art form.
ScreenshotThe Quarter's splash screen, as captured by ansi2img. The Quarter (based on Duh Draw, and via that, on the DOS application The Draw) was the ANSI editor from Project Megistos.
RenderConsole FrameworkOne of my mantras is: nothing is worth doing unless it's reusable and generalised. To do this, IBM PC Text Mode FontsUntil the advent of the VGA, IBM PCs had a range of 256 visible glyphs per font1. The IBM MDA, the first display adapter (a text-only, monochrome device) offered a 9x14 font, but this is not (as of yet) supported by this program. The IBM CGA supported 8x8 fonts (200 scanlines). The font was in ROM and could not be changed in software. The IBM EGA was the first commonly used IBM card to support soft fonts of various sizes, the usual being 8x14. It also included the CGA 8x8 font for compatibility. The IBM VGA contained all the CGA and EGA fonts and added an 8x16 font. This is rendered as 9x16 at the default text resolution of 720x480, which is still with us. EGA and VGA fonts are simple arrays of bytes. Each character from 0 to 255 is represented by 8, 14, or 16 bytes. The least significant bit of each byte represented the rightmost pixel of each character cell. This resulted in fonts of 2,048, 3,584 and 4,096 bytes. This program supports any such uncompressed, unencoded font without metadata, including fonts with arbitrary character heights (it will do its best to guess). A default VGA font for CP437, the US codepage, is built into the program. DownloadBoth ANSI to Bitmap converter and RenderConsole Framework
LicenseIt's all available under the terms of the GNU Public License. The example files in the distribution are © their respective artists. Try It Online!If you'd rather not install anything on your computer, you can use the ANSI converter online. The online version does everything the offline one does, except you're limited to the few fonts it has (CGA, EGA, and VGA, plus Greek versions2).
|
|
|
|
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...
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!