]> git.imager.perl.org - imager.git/blame - samples/tk-photo.pl
extend some variable types to avoid overflows for mediancut
[imager.git] / samples / tk-photo.pl
CommitLineData
44da52d3
TC
1#!perl -w
2use strict;
3use Tk;
4use Tk::Photo;
5use MIME::Base64;
6use Tk::PNG;
7use Imager;
8
9my $image = Imager->new(xsize=>100, ysize=>100);
10
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);
15
16my $image_data;
17$image->write(data =>\$image_data, type=>'png')
18 or die "Cannot save image: ", $image->errstr;
19
20# supplying binary data didn't work, so we base64 encode it
21$image_data = encode_base64($image_data);
22
23my $main = MainWindow->new;
24my $tk_image = $main->Photo(-data => $image_data);
25$main->Label(-image=>$tk_image)->pack;
26MainLoop;
27
28=head1 NAME
29
5715f7c3
TC
30=for stopwords tk-photo.pl
31
44da52d3
TC
32tk-photo.pl - display an Imager image under Tk
33
34=head1 SYNOPSIS
35
5d36cf24 36 $ perl tk-photo.pl
44da52d3
TC
37
38=head1 DESCRIPTION
39
40Simple code to make a Tk::Photo object from an Imager image.
41
42This works by:
43
44=over
45
46=item 1.
47
48write the image data to a scalar in PNG format
49
50=item 2.
51
52Base64 decode the data
53
54=item 3.
55
56read() it into the photo object, supplying the Base64 encoded data to
57the C<-data> parameter.
58
59=back
60
61=head1 REVISION
62
63$Revision$
64
65=head1 AUTHOR
66
5b480b14 67Tony Cook <tonyc@cpan.org>
44da52d3
TC
68
69=cut