Image::Base::Tk::Photo -- draw with Tk::Photo
use Image::Base::Tk::Photo; my $image = Image::Base::Tk::Photo->new (-for_widget => $mw, -width => 100, -height => 100); $image->rectangle (0,0, 99,99, 'white'); $image->xy (20,20, 'black'); $image->line (50,50, 70,70, '#FF00FF'); $image->line (50,70, 70,50, '#0000AAAA9999'); $image->save ('/some/filename.png');
Image::Base::Tk::Photo is a subclass of
Image::Base to create or update image files using the
Tk::Photo module from Perl-Tk.
See Tk::Photo for the supported file formats. Perl-Tk 804 includes
PNG, JPEG, XPM, XBM, GIF, BMP, PPM/PGM TIFF separate Tk::TIFF module
Tk::Photo requires a
Tk::MainWindow and so an X display (etc), though there's no need to actually display the MainWindow. Drawing operations use the Photo pixel/rectangle
For reference, to draw arbitrary graphics in Perl-Tk the choice is between a
Tk::Canvas with arcs etc, or a
Tk::Photo of pixels which is set as the
-image of a
Tk::Label or similar. Is that right? No drawing area widget as such?
Colour names are anything recognised by Tk_GetColor(3tk), plus "None",
X server names usually /etc/X11/rgb.txt #RGB hex #RRGGBB hex #RRRGGGBBB hex #RRRRGGGGBBBB hex None transparent
The hex forms end up going to Xlib which means the shorter ones are padded with zeros, so "#FFF" is "#F000F000F000" which is a light grey rather than white. See X(7) "COLOR NAMES".
"None" means a transparent pixel, as per
See "FUNCTIONS" in Image::Base for the behaviour common to all Image-Base classes.
$image = Image::Base::Tk::Photo->new (key=>value,...)
Create and return a new image object. It can be given an existing
$image = Image::Base::Tk::Photo->new (-tkphoto => $tkphoto);
Or it can create a new
-for_widget option gives a widget hierarchy where the new
Tk::Photo will be used. A toplevel
Tk::MainWindow is suitable.
$image = Image::Base::Tk::Photo->new (-for_widget => $widget);
-height size can be given. Zero or omitted gives the usual auto-sizing of
$image = Image::Base::Tk::Photo->new (-for_widget => $widget, -width => 200, -height => 100);
Or a file can be read,
$image = Image::Base::Tk::Photo->new (-for_widget => $widget, -file => '/some/filename.xpm');
Tk::Photo must be explicitly destroyed with
$tkphoto->delete() the same as all
Tk::Image types (see Tk::Image).
Image::Base::Tk::Photo doesn't currently do that in its own destruction. Should it do so when it created the photo? But probably don't want to destroy when merely set in as a
$new_image = $image->new (key=>value,...)
This is supposed to clone the image object, but it's not implemented yet. How to clone a
Read the current
-file, or set
$filename and then read.
The file format is recognised automatically by
Tk::Photo from the formats registered. Some formats are builtin, but for PNG, JPEG and TIFF the corresponding format modules
Tk::TIFF must be used first. For example,
use Tk::PNG; $image->load ('/my/filename.png');
-file, or with a
$filename argument set
-file then save to that.
The saved file format is taken from
-file_format (see "ATTRIBUTES" below) if that was set, either from a
load() or explicit
For convenience, when saving PNG, JPEG and TIFF the necessary
Tk::TIFF module is loaded automatically. Any other non-builtin formats will require their modules loaded before attempting a
Setting these changes the size of the image.
The file format as a string like "png" or "jpeg", or
undef if unknown or never set.
-file_format is the format read. Setting
-file_format can change the format for a subsequent
There's no attempt to check or validate the
-file_format value since it's possible to add new formats to Tk::Photo at run time. Expect
save() to croak if the format is unknown.
Image-Base-Tk is Copyright 2010, 2011, 2012 Kevin Ryde
Image-Base-Tk is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.
Image-Base-Tk is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Image-Base-Tk. If not, see <http://www.gnu.org/licenses/>.