Hello!
This newbie is trying to use the GD module with an ActiveState Perl installation. I've had good luck with using Tk for making GUIs, and graphs, but Tk isn't so good for PRINTING or SAVING a canvas. So.. I'm trying out GD. But the "hello world" code found on the web doesn't spawn a window, it just dumps junk to the console... Actually no GD example I've found actually displays anything. What am I missing? The code is below. Thanks much!!
#!/usr/bin/perl -w
use GD;
# create a new image
$image = new GD::Image(100,100);
# allocate some colors
$white = $image->colorAllocate(255,255,255);
$black = $image->colorAllocate(0,0,0);
$red = $image->colorAllocate(255,0,0);
$blue = $image->colorAllocate(0,0,255);
# make the background transparent and interlaced
$image->transparent($white);
$image->interlaced('true');
# Put a black frame around the picture
$image->rectangle(0,0,99,99,$black);
# Draw a blue oval
$image->arc(50,50,95,75,0,360,$blue);
# And fill it with red
$image->fill(50,50,$red);
# make sure we are writing to a binary stream
binmode STDOUT;
# Convert the image to PNG and print it on standard
# output
print $image->png;
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.