Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Imager drawing question

by tonyc (Pilgrim)
on Sep 28, 2005 at 02:31 UTC ( #495605=note: print w/ replies, xml ) Need Help??


in reply to Imager drawing question

You don't really provide a lot of context - is this code in a CGI script? are you trying to display it from Tk?

The changes you make to an Imager object won't be displayed or written anywhere until you call the write method.

There's both sample code and documentation showing how to return an image from a CGI script.

If you want to see what an image looks like from the console, for example, if you're fiddling with the code and want to see what you're producing, write the image to a file and then use some sort of image viewer to view the image.

Another option is to use Tk to view the image, but it's kind of clumsy:

#!perl -w use strict; use Tk; use Tk::Photo; use MIME::Base64; use Tk::PNG; use Imager; my $image = Imager->new(xsize=>100, ysize=>100); # draw something simple here, you'll probably do something more comple +x $image->box(filled=>1, color=>'blue'); $image->box(filled=>1, color=>'red', xmin=>20, ymin=>20, xmax=>79, ymax=>79); my $image_data; $image->write(data =>\$image_data, type=>'png') or die "Cannot save image: ", $image->errstr; # supplying binary data didn't work, so we base64 encode it $image_data = encode_base64($image_data); my $main = MainWindow->new; my $tk_image = $main->Photo(-data => $image_data); $main->Label(-image=>$tk_image)->pack; MainLoop;


Comment on Re: Imager drawing question
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2014-10-02 09:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (52 votes), past polls