1=head1 NAME 2 3Image::Base - base class for loading, manipulating and saving images. 4 5=head1 SYNOPSIS 6 7This class should not be used directly. Known inheritors are Image::Xbm and 8Image::Xpm. 9 10 use Image::Xpm ; 11 12 my $i = Image::Xpm->new( -file => 'test.xpm' ) ; 13 $i->line( 1, 1, 3, 7, 'red' ) ; 14 $i->ellipse( 3, 3, 6, 7, '#ff00cc' ) ; 15 $i->rectangle( 4, 2, 9, 8, 'blue' ) ; 16 17If you want to create your own algorithms to manipulate images in terms of 18(x,y,colour) then you could extend this class (without changing the file), 19like this: 20 21 # Filename: mylibrary.pl 22 package Image::Base ; # Switch to this class to build on it. 23 24 sub mytransform { 25 my $self = shift ; 26 my $class = ref( $self ) || $self ; 27 28 # Perform your transformation here; might be drawing a line or filling 29 # a rectangle or whatever... getting/setting pixels using $self->xy(). 30 } 31 32 package main ; # Switch back to the default package. 33 34Now if you C<require> mylibrary.pl after you've C<use>d Image::Xpm or any 35other Image::Base inheriting classes then all these classes will inherit your 36C<mytransform()> method. 37 38=head1 DESCRIPTION 39 40=head2 new_from_image() 41 42 my $bitmap = Image::Xbm->new( -file => 'bitmap.xbm' ) ; 43 my $pixmap = $bitmap->new_from_image( 'Image::Xpm', -cpp => 1 ) ; 44 $pixmap->save( 'pixmap.xpm' ) ; 45 46Note that the above will only work if you've installed Image::Xbm and 47Image::Xpm, but will work correctly for any image object that inherits from 48Image::Base and respects its API. 49 50You can use this method to transform an image to another image of the same 51type but with some different characteristics, e.g. 52 53 my $p = Image::Xpm->new( -file => 'test1.xpm' ) ; 54 my $q = $p->new_from_image( ref $p, -cpp => 2, -file => 'test2.xpm' ) ; 55 $q->save ; 56 57=head2 line() 58 59 $i->line( $x0, $y0, $x1, $y1, $colour ) ; 60 61Draw a line from point ($x0,$y0) to point ($x1,$y1) in colour $colour. 62 63=head2 ellipse() 64 65 $i->ellipse( $x0, $y0, $x1, $y1, $colour ) ; 66 67Draw an oval enclosed by the rectangle whose top left is ($x0,$y0) and bottom 68right is ($x1,$y1) using a line colour of $colour. 69 70=head2 rectangle() 71 72 $i->rectangle( $x0, $y0, $x1, $y1, $colour, $fill ) ; 73 74Draw a rectangle whose top left is ($x0,$y0) and bottom right is ($x1,$y1) 75using a line colour of $colour. If C<$fill> is true then the rectangle will be 76filled. 77 78=head2 new() 79 80Virtual - must be overridden. 81 82Recommend that it at least supports C<-file> (filename), C<-width> and 83C<-height>. 84 85=head2 new_from_serialised() 86 87Not implemented. Recommended for inheritors. Should accept a string serialised 88using serialise() and return an object (reference). 89 90=head2 serialise() 91 92Not implemented. Recommended for inheritors. Should return a string 93representation (ideally compressed). 94 95=head2 get() 96 97 my $width = $i->get( -width ) ; 98 my( $hotx, $hoty ) = $i->get( -hotx, -hoty ) ; 99 100Get any of the object's attributes. Multiple attributes may be requested in a 101single call. 102 103See C<xy> get/set colours of the image itself. 104 105=head2 set() 106 107Virtual - must be overridden. 108 109Set any of the object's attributes. Multiple attributes may be set in a single 110call; some attributes are read-only. 111 112See C<xy> get/set colours of the image itself. 113 114=head2 xy() 115 116Virtual - must be overridden. Expected to provide the following functionality: 117 118 $i->xy( 4, 11, '#123454' ) ; # Set the colour at point 4,11 119 my $v = $i->xy( 9, 17 ) ; # Get the colour at point 9,17 120 121Get/set colours using x, y coordinates; coordinates start at 0. 122 123When called to set the colour the value returned is class specific; when 124called to get the colour the value returned is the colour name, e.g. 'blue' or 125'#f0f0f0', etc, e.g. 126 127 $colour = xy( $x, $y ) ; # e.g. #123456 128 xy( $x, $y, $colour ) ; # Return value is class specific 129 130We don't normally pick up the return value when setting the colour. 131 132=head2 load() 133 134Virtual - must be overridden. Expected to provide the following functionality: 135 136 $i->load ; 137 $i->load( 'test.xpm' ) ; 138 139Load the image whose name is given, or if none is given load the image whose 140name is in the C<-file> attribute. 141 142=head2 save() 143 144Virtual - must be overridden. Expected to provide the following functionality: 145 146 $i->save ; 147 $i->save( 'test.xpm' ) ; 148 149Save the image using the name given, or if none is given save the image using 150the name in the C<-file> attribute. The image is saved in xpm format. 151 152=head1 CHANGES 153 1542000/05/05 155 156Added some basic drawing methods. Minor documentation changes. 157 158 1592000/05/04 160 161Created. 162 163 164=head1 AUTHOR 165 166Mark Summerfield. I can be contacted as <summer@perlpress.com> - 167please include the word 'imagebase' in the subject line. 168 169=head1 COPYRIGHT 170 171Copyright (c) Mark Summerfield 2000. All Rights Reserved. 172 173This module may be used/distributed/modified under the LGPL. 174 175=cut 176 177