Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: Imager drawing question

by tonyc (Friar)
on Sep 28, 2005 at 02:31 UTC ( [id://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;

Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (6)
As of 2024-05-18 06:58 GMT
Find Nodes?
    Voting Booth?

    No recent polls found