Blog Post RSS ?

Blogs » PHP » ASCII diagrams to image
 

ASCII diagrams to image

by Harry Fuecks

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…

If you liked this blog, share the love:

  • Save to Del.icio.us

This post has 12 responses so far

  1. umm…

    i have python and jave on my other box…

     
  2. 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?

     
  3. 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?

     
  4. -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.

     
  5. […] responses to this entry through the RSS 2.0 feed. :) Responses are currently closed, but you can trackback from your ownsite. […]

     

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

     
  8. 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).

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

     
  10. 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.

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

     
  12. 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.

     

Sponsored Links

Leave a response

You are not logged in, log in with your SitePoint Forum username and password.

-OR- Post Anonymously

* Make sure any code samples are escaped (i.e. ‘<b>’ becomes ‘&lt;b&gt;’).

If not logged in, your comments will be placed in a moderation queue. This means your comment may not appear until one of our moderators approves it.

SitePoint Marketplace

Buy and sell Websites, templates, domain names, hosting, graphics and more.

Logo Design, Web page Design and more!

99designs

  • Custom logo designs created ‘just for you’.
  • Pick the design you like best.
  • Only pay if you’re satisfied with the result.

The Web Site Revenue Maximizer

New Release

Free PDF Download:

101 Ways To Make Money From Your Website!

Free eBook! Firefox Revealed