Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

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

by sleepingsquirrel (Hermit)
on Jan 25, 2005 at 22:29 UTC ( #425064=note: print w/ replies, xml ) Need Help??


in reply to Re^2: What would you guys recommend for generating graphic-based output?
in thread What would you guys recommend for generating graphic-based output?

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.


Comment on Re^3: What would you guys recommend for generating graphic-based output?
Download Code
Re^4: What would you guys recommend for generating graphic-based output?
by sleepingsquirrel (Hermit) on Jan 26, 2005 at 16:21 UTC
    This is what the output looks like for the above program.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2014-09-20 19:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (160 votes), past polls