ASCII diagrams to image

In:


    +---------+         +---------+     +---------+
    |  Shape  |         |  Line   |     |  Point  |
    +---------+         +---------+   2 +---------+
    | draw    +<--------+ start   +----O+ x       |
    | move    +<-+      | end     |     | y       |
    +---------+        +---------+     +---------+
                                     
                       +---------+
                     +--+ Circle  |
                        +---------+
                        | center  |
                        | radius  |
                        +---------+

Out:

UML from ASCII

Seems this is a to-be-released feature of docutils (Python) called aafigure – source available here – also see the README before and after. To install you’d need Python + PIL – after that download the various .py files from here and run aafigure.py --help from the command line. Able to generate svg, png or jpg.

Very cool. It’s not yet quite so clever to handle any old diagram from JavE, which doesn’t necessarily produce clean lines (depends on the drawing tools you used) and Iñtërnâtiônàlizætiøn is problem but this would be very handy for wikis and similar. Just needs porting to PHP…

Free book: Jump Start HTML5 Basics

Grab a free copy of one our latest ebooks! Packed with hints and tips on HTML5's most powerful new features.

  • Dr Livingston

    umm…

    i have python and jave on my other box…

  • malikyte

    Just needs porting to PHP…

    -offtopic-
    So, when will Sitepoint invest some time into a Python section here on the Sitepoint blogs? It seems we have the talent, experience, and willingness for it. Great addition to keep it still within the PHP topic area though with that last sentence, Harry. ^_^
    -offtopic-

    This seems like a great tool for rendering diagram-specific models from JavE, but what happens if/when a not-so-perfectly-rendered diagram is sent to this? Does it support error handling methods and exceptions/extendability?

  • Ren

    Reminds me of the old IBM DOS charset, it had all the funky box drawing characters in it.

    How painful is it to actually draw with ASCII tho? If you need a tool to draw it, why not go and use SVG?

  • http://www.phppatterns.com HarryF

    -offtopic-
    So, when will Sitepoint invest some time into a Python section here on the Sitepoint blogs? It seems we have the talent, experience, and willingness for it. Great addition to keep it still within the PHP topic area though with that last sentence, Harry. ^_^
    -offtopic-

    When posting it needs a “Python” checkbox. And having a real Python blogger would help ;) I guess anyone motived to blog on Python should try here: http://www.sitepoint.com/contact

    but what happens if/when a not-so-perfectly-rendered diagram is sent to this? Does it support error handling methods and exceptions/extendability?

    It seems robust in the sense that I haven’t been able to break it – you still get “something” out of the far end but, for example with dotted lines, they are not interpreted as a line – just a series of dots.

    How painful is it to actually draw with ASCII tho? If you need a tool to draw it, why not go and use SVG?

    Doing large ASCII diagrams from hand is a pain in terms of filling in / aligning stuff with whitespace. But it is quite popular – emacs has a tool for this, for example. If doing this I tend to start with JavE then fine tune by hand.

    The advantage is you can have the image source truly inline with the document (just “plain” text, no browser plugins for non-Firefox users needed). Also Open Source SVG tools aren’t so well evolved – there’s inkscape – http://inkscape.org/ – otherwise I guess dia (http://www.gnome.org/projects/dia/) can export SVG. And tools like visitors (http://www.hping.org/visitors/) produce ASCII reports which could be turned into bar chart images with this.

  • Pingback: The Boars Head Tavern » Blog Archive » And so it begins….

  • Anonymous


  • http://www.gammaworld.org/mutant/ mutant

    This is kinda cool, but only in a golly gee sort of fashion. I don’t see very many practical uses for this.

  • kyberfabrikken

    Isn’t graphviz a better way to go? dot-markup is really simple, and rather than describe how to render the graph, it describes what the graph should contain (and leaves it to the layout engine to arrange it).

  • Eugene Panin

    What is the goal of this ascii->graphics conversion? Just for fun?

  • http://macosbrain.com macosbrain

    wow very nice. but the drawing of ascii diagrams takes me much longer than the drawing of an simple image. so i think image to ascii would be better.

  • paul

    You could draw these diagams with: http://www.asciidrawer.com

  • http://wwwlab.org wwwlab

    This is very cool, I’ve already had a play about with it and I’m hoping for a PHP port very soon. I’d like to use it to make a website to display my family tree.