Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Graphical program

by federico-perlmonks (Novice)
on Apr 17, 2016 at 13:10 UTC ( [id://1160717]=perlquestion: print w/replies, xml ) Need Help??

federico-perlmonks has asked for the wisdom of the Perl Monks concerning the following question:

Hello everyone, I am trying to write a graphical program with the following tasks:
1) Import an image in .svg that I have in a local folder; The image is a map of a city with a grid I added with Inkscape, so that the city is divided in "sectors";
2) Print some text in specific points, that is in each sector (for example a random number).

I did not understand much of what I found on the web and since I have no idea on how to do it, I did not write any code. I would be most thankful if someone could explain me just how to do it.

Replies are listed 'Best First'.
Re: Graphical program
by RichardK (Parson) on Apr 17, 2016 at 14:29 UTC

    You don't know how to do what?

    If you need to understand SVG then is a good place to start.

    Or if it's just the perl part, there are modules in CPAN for dealing with SVG: see SVG for one.

      It was for the perl part... Thank you for your help, I read more carefully the CPAN page for SVG module and I solved my problem.


      ++ for an excellent answer!


      "Well done is better than well said." - Benjamin Franklin

Re: Graphical program
by BrowserUk (Patriarch) on Apr 17, 2016 at 15:38 UTC

    Are you saying you want to:

    • load the .svg, add some text, and then re-write the .svg with the added text?
    • load the .svg and display it with some text added; leaving the original .svg unmodified?
    • load the .svg; allow the user to interact with your program to add some text at specific points on the image and then save the modified image to disk?

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
    In the absence of evidence, opinion is indistinguishable from prejudice.

      The second one: load the .svg, add the text, save and display the modified image.

      I think I am supposed to do something like this:

      #!/usr/bin/perl use warnings; use strict; use SVG; # Open the file whicw will contain the modified image. open(MAP_OUT, ">output.svg") || die "Error: unable to open output.svg: + $!\n"; # Create the SVG object. my $svg = SVG->new( width => 1500, height => 1500 ); # Load the image. my $map = $svg->image( x => 0, y => 0, width => 1500, height => 1500, '-href' => "map.svg", id => "image_1" ); # Add the text. my $text = $svg->text( id => "text_1", x => 40, y => 80, -cdata => "something" ); # Add some more text... # Print the xml text on the output file. print MAP_OUT $svg->xmlify; # Open the .svg image with firefox. system(firefox, output.svg);

      Is it OK?

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1160717]
Approved by stevieb
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-04-18 21:13 GMT
Find Nodes?
    Voting Booth?

    No recent polls found