02 Feb 2012 20:29:52 UTC
- Distribution: Image-Base-Tk
- Module version: 3
- Source (raw)
- Browse (raw)
- How to Contribute
- Testers (338 / 0 / 0)
- KwaliteeBus factor: 1
- 12.33% Coverage
- License: open_source
- Perl: v5.6.0
- Activity24 month
- Download (44.77KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest versionKRYDE Kevin Rydeand 1 contributors
- Kevin Ryde
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::Photois a subclass of
Image::Baseto create or update image files using the
Tk::Photomodule 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::MainWindowand 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::Canvaswith arcs etc, or a
Tk::Photoof pixels which is set as the
Tk::Labelor 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_widgetoption gives a widget hierarchy where the new
Tk::Photowill be used. A toplevel
$image = Image::Base::Tk::Photo->new (-for_widget => $widget);
-heightsize 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::Photomust be explicitly destroyed with
$tkphoto->delete()the same as all
Tk::Imagetypes (see Tk::Image).
Image::Base::Tk::Photodoesn'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
$filenameand then read.
The file format is recognised automatically by
Tk::Photofrom the formats registered. Some formats are builtin, but for PNG, JPEG and TIFF the corresponding format modules
Tk::TIFFmust be used first. For example,
use Tk::PNG; $image->load ('/my/filename.png');
-file, or with a
-filethen save to that.
The saved file format is taken from
-file_format(see "ATTRIBUTES" below) if that was set, either from a
For convenience, when saving PNG, JPEG and TIFF the necessary
Tk::TIFFmodule 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
undefif unknown or never set.
-file_formatis the format read. Setting
-file_formatcan change the format for a subsequent
There's no attempt to check or validate the
-file_formatvalue 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/>.
Module Install Instructions
To install Image::Base::Tk::Photo, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell install Image::Base::Tk::Photo
For more information on module installation, please visit the detailed CPAN module installation guide.