9 my $image = Imager->new(xsize=>100, ysize=>100);
11 # draw something simple here, you'll probably do something more complex
12 $image->box(filled=>1, color=>'blue');
13 $image->box(filled=>1, color=>'red',
14 xmin=>20, ymin=>20, xmax=>79, ymax=>79);
17 $image->write(data =>\$image_data, type=>'png')
18 or die "Cannot save image: ", $image->errstr;
20 # supplying binary data didn't work, so we base64 encode it
21 $image_data = encode_base64($image_data);
23 my $main = MainWindow->new;
24 my $tk_image = $main->Photo(-data => $image_data);
25 $main->Label(-image=>$tk_image)->pack;
30 tk-photo.pl - display an Imager image under Tk
38 Simple code to make a Tk::Photo object from an Imager image.
46 write the image data to a scalar in PNG format
50 Base64 decode the data
54 read() it into the photo object, supplying the Base64 encoded data to
55 the C<-data> parameter.
65 Tony Cook <tony@imager.perl.org>