martell has asked for the wisdom of the Perl Monks concerning the following question:

Dear monks

I have following challenge. I want to create images from a database containing our technical infrastructure. The symbols i have to use are the archimate symbols. I want to construct a drawing that displays the business objects (bo) contained in application components.

------------------------------- | application component | ----- -------- -------- | | | | bo | | bo | | ----- |------| |------| | | | | | | | ----- | | | | | | | -------- -------- | ----- | | | | | | | -------------------------------

I though SVG are the way to go. I can find some very nice svg images representing the business object and the application component.

Basically i want to import the svg drawing of the business object in my script, add the name of the object from the database. Repeat for all business objects in the database and put the business objects on the image. Then scale the application component svg and put around the business objects. Repeat for all application components. Finally generate the drawing to png or jpg and send it to a html page.

I have looked to GD:SVG, but it doesn't import the given svg images and can't scale. SVG seems complex to learn.

Does anyone know which perl modules I can use to accomplish the drawing part as simple as possible or give some code snippets i can use?

Kind regards

Martell

Replies are listed 'Best First'.
Re: SVG manipulation
by chrestomanci (Priest) on Apr 28, 2011 at 08:24 UTC

    I have done this sort of thing in the past using templating.

    First I drew my design in Inkscape, where it is easy to do complex things. I put in bit of place holder text for the labels that would be replaced with templates later. When I was happy, I saved the SVG from Inkscape, and opened it in a text editor. I found my bits of place holder text and replaced them with with template tags.

    Finally I wrote my script to load the svg with template tags, and replace those tags with the desired text from my database.

    For that project, I used Text::Template, though you could also consider using Template::Toolkit which appears to be much more fashionable at the moment.

      This seems a nice approach for my need. Hadn't though about it. I will give it a quick spin to see if this a solution. Thanks Martell
Re: SVG manipulation
by luis.roca (Deacon) on Apr 27, 2011 at 21:37 UTC

    I have looked to GD:SVG, but it doesn't import the given svg images and can't scale. SVG seems complex to learn.

    Does anyone know which perl modules I can use to accomplish the drawing part as simple as possible or give some code snippets i can use?

    I realize you asked for Perl modules (AM provided a few good ones you should definitely check out.) to accomplish the drawings but this may be another option:

    If you're uneasy about learning SVG, although it's really not as hard as you may be thinking, you can try the open source vector program Inkscape for creating the drawings. SVG is Inkscape's native file format and you can even view a drawing's markup in it's XML editor. You can also do batch automation which should take care of your resizing and conversions to png or jpeg.

    You can work with Inkscape from the command line which — I believe — will give you the ability to script it with Perl. Other more prolific Inkscape users may be able to confirm/deny that for you.

    Hope this helps. Good luck!
    Luis

    "...the adversities born of well-placed thoughts should be considered mercies rather than misfortunes." — Don Quixote
Re: SVG manipulation
by Anonymous Monk on Apr 27, 2011 at 19:56 UTC

      SVG::Graph looks like a module to plot data into graph like you do with Excel. I'm trying to construct a drawing, more like a building plan. I fail to see how this module can help me or am I missing something?

      Kind regards

      Martell

Re: SVG manipulation
by zentara (Cardinal) on Apr 28, 2011 at 15:14 UTC
    I played with your concept awhile back. I found autotrace.

    Then I used the following script to convert.

    Gtk2 also has SVG capabilities, see Gnome2::Rsvg

    #!/usr/bin/perl use warnings; use strict; use Image::Magick; my $infile = $ARGV[0]; (my $filebase) = $infile =~ /(.*)\.(\w+)$/; my $p = new Image::Magick; $p->Read($infile); my $outbmp = $filebase.'.'.'bmp'; $p->Write($outbmp) or warn "@!"; my $fin = $outbmp; my $fout = $filebase.'.svg'; my @options = qw( --despeckle-level 8 --corner-always-threshold 60 --corner-surround 60 --tangent-surround 3 --color-count 256 --corner-threshold 100 --despeckle-tightness 2 --error-threshold 2 --filter-iterations 4 --line-reversion-threshold .01 --line-threshold 1 ); system ("./autotrace --output-format svg --output-file $fout @options + $fin"); __END__ adjColor = gtk.Adjustment(256, lower=0, upper=256, step_incr=1, page_i +ncr=0, page_size=0) adjColAlwThresh = gtk.Adjustment(60, lower=2, upper=180, step_incr=1, +page_incr=10, page_size=0) adjCornSur = gtk.Adjustment(60, lower=2, upper=180, step_incr=1, page_ +incr=20, page_size=0) adjCornTh = gtk.Adjustment(100, lower=2, upper=180, step_incr=1, page_ +incr=10, page_size=0) adjDespLev = gtk.Adjustment(8, lower=0, upper=20, step_incr=1, page_in +cr=0, page_size=0) adjDespTig = gtk.Adjustment(2, lower=0, upper=8, step_incr=0.1, page_i +ncr=1, page_size=0) adjErrThr = gtk.Adjustment(2, lower=.1, upper=10, step_incr=0.1, page_ +incr=1, page_size=0) adjFiltIt = gtk.Adjustment(4, lower=1, upper=16, step_incr=1, page_inc +r=0, page_size=0) adjLineRevThr = gtk.Adjustment(0.01, lower=0.01, upper=0.16, step_incr +=0.01, page_incr=1, page_size=0) adjLineThr = gtk.Adjustment(1, lower=1, upper=20, step_incr=1, page_in +cr=0, page_size=0) adjTangSur = gtk.Adjustment(3, lower=1, upper=16, step_incr=1, page_in +cr=0, page_size=0) adjNumCol = gtk.Adjustment(0, lower=0, upper=256, step_incr=1, page_in +cr=20, page_size=0)

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh

      Nice program. It is however not what i'm looking for.

      Maybe a little more explanation about my problem. Suppose I have in my database an application component with 6 business object and another application component with 3 business objects inside.

      I'm trying to generate an image that will display 2 application components. The first will be bigger and containing 2 rows of 3 business objects. The second will have 1 row of 3 business objects.

      To generate the image, I want to take a svg image representing the business object and copy it six times in on a grid. Next I will take the svg image representing the application component, stretch it so its boundaries are bigger then the grid of the six business objects and past the six objects inside.

      I hope the svg manipulation would simplify the construction of the drawing. To construct the image using png parts is possible but cumbersome and not easily maintainable if they suddenly want another symbol.

      Nevertheless the program you suggested is nice to know. At many other occasions I wished I had something like that. And now I have :)

      Kind regards

      Martell

        After reading what you are trying to do, my first thought is to use a Canvas type widget, since you are talking about resizing components. For instance, a Tk Canvas, and all other Canvas type widgets, will let you programmically draw and resize widgets, and the advanced Canvases will let you zoom, as in Tk::Zinc.

        Anyways, a Tk canvas will let you construct your custom gridwork, fill it in with appropriately scaled fonts, and export the whole thing as a pdf. See Tk Patio/Office layout designer for example.

        However, if this is running on a server, Canvases need an X server, so it may not be useful to you.


        I'm not really a human, but I play one on earth.
        Old Perl Programmer Haiku ................... flash japh