Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: What would you guys recommend for generating graphic-based output?

by zentara (Archbishop)
on Jan 25, 2005 at 19:00 UTC ( [id://424993]=note: print w/replies, xml ) Need Help??


in reply to What would you guys recommend for generating graphic-based output?

If you wanted to reconsider Tk, maybe the Tk::Canvas would do the trick for you. You can easily setup an invisible grid on the canvas, then put whatever you want at each point, anchoring it to "north' or 'center', or whatever. You can mix Text and small graphics, and even draw outlines around them for emphasis. GD will do that, but it's alot trickier with GD, getting colors and fonts just right.

Then you can take a png snaphot of the Canvas with Tk::WinPhoto, or export it to postscript.

I think you will find Tk has more flexibility than GD, but it really depends on what your needs are.


I'm not really a human, but I play one on earth. flash japh
  • Comment on Re: What would you guys recommend for generating graphic-based output?

Replies are listed 'Best First'.
Re^2: What would you guys recommend for generating graphic-based output?
by FrankRizzo (Acolyte) on Jan 25, 2005 at 20:14 UTC
    OK, the more important question, does anyone have any links to examples? I'm a "string in, string out" kinda guy, trying to get by with as little graphics work as I possibly can, as this is the LAST ITEM on the project plan, and I'm ready to be done! Thanks Guys! Frank
      Needs ghostscript installed, produces a file "tmp.png".
      #!/usr/bin/perl -w %stats = (Foo => 14, Bar => 10, Baz => 5, Box => 8); $title = "Widgets, Inc"; $ps_preamble = <<PS_END; %!PS-Adobe-2.0 /big /Helvetica findfont 20 scalefont def /tiny /Helvetica findfont 9 scalefont def /box { newpath moveto lineto lineto lineto closepath } def 0 setgray big setfont 612 ($title) stringwidth pop sub 2 div 648 moveto ($title) show 1 setlinewidth 72 72 72 720 540 720 540 72 box stroke tiny setfont PS_END open (GS, "|gs -dSAFER -dBATCH -dNOPAUSE -q -r80 -sDEVICE=png16m". " -sOutputFile=tmp.png - ") or die "Can't start Ghostscript" +; print GS $ps_preamble; my $n = keys %stats; my $w = 396/$n; my $i=0; for (keys %stats) { my $x = $i*$w+126; my $y = $stats{$_} * 30 + 108; print GS "$x 90 moveto\n($_) show\n"; print GS "0.5 0 0.8 setrgbcolor\n"; print GS "$x 108 ", "$x $y ", $x+$w/2, " $y ", $x+$w/2, " 108 box fill\n"; print GS "0 setgray\n"; $i++; } print GS "showpage\n"; close(GS);


      -- All code is 100% tested and functional unless otherwise noted.
        This is what the output looks like for the above program.
      I'll post a little tk snippet later today, which exports a canvas full of text to png. (I'll have to make one up :-) ) Also I just noticed a new version of "pngwriter" was just announced on freshmeat.

      About: The PNGwriter library, which requires libpng, allows you to plot to a 48-bit PNG file, saving it directly to disk. Plotting is as easy as specifying the red, green, and blue values and the x, y coordinates of the pixel. It includes functions for plotting simple geometric shapes (circle, rect, line), plotting text (UTF-8 support for Asian languages), reading the colour of a pixel, reading in a whole PNG file (great for image analysis), plotting and reading in HSV colourspace, and many others that might come in handy.

      pngwriter


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://424993]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-04-19 07:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found