1Base(3)               User Contributed Perl Documentation              Base(3)
2
3
4

NAME

6       Image::Base - base class for loading, manipulating and saving images.
7

SYNOPSIS

9       This class should not be used directly. Known inheritors are Image::Xbm
10       and Image::Xpm.
11
12           use Image::Xpm ;
13
14           my $i = Image::Xpm->new( -file => 'test.xpm' ) ;
15           $i->line( 1, 1, 3, 7, 'red' ) ;
16           $i->ellipse( 3, 3, 6, 7, '#ff00cc' ) ;
17           $i->rectangle( 4, 2, 9, 8, 'blue' ) ;
18
19       If you want to create your own algorithms to manipulate images in terms
20       of (x,y,colour) then you could extend this class (without changing the
21       file), like this:
22
23           # Filename: mylibrary.pl
24           package Image::Base ; # Switch to this class to build on it.
25
26           sub mytransform {
27               my $self  = shift ;
28               my $class = ref( $self ) ⎪⎪ $self ;
29
30               # Perform your transformation here; might be drawing a line or filling
31               # a rectangle or whatever... getting/setting pixels using $self->xy().
32           }
33
34           package main ; # Switch back to the default package.
35
36       Now if you "require" mylibrary.pl after you've "use"d Image::Xpm or any
37       other Image::Base inheriting classes then all these classes will
38       inherit your "mytransform()" method.
39

DESCRIPTION

41       new_from_image()
42
43           my $bitmap = Image::Xbm->new( -file => 'bitmap.xbm' ) ;
44           my $pixmap = $bitmap->new_from_image( 'Image::Xpm', -cpp => 1 ) ;
45           $pixmap->save( 'pixmap.xpm' ) ;
46
47       Note that the above will only work if you've installed Image::Xbm and
48       Image::Xpm, but will work correctly for any image object that inherits
49       from Image::Base and respects its API.
50
51       You can use this method to transform an image to another image of the
52       same type but with some different characteristics, e.g.
53
54           my $p = Image::Xpm->new( -file => 'test1.xpm' ) ;
55           my $q = $p->new_from_image( ref $p, -cpp => 2, -file => 'test2.xpm' ) ;
56           $q->save ;
57
58       line()
59
60           $i->line( $x0, $y0, $x1, $y1, $colour ) ;
61
62       Draw a line from point ($x0,$y0) to point ($x1,$y1) in colour $colour.
63
64       ellipse()
65
66           $i->ellipse( $x0, $y0, $x1, $y1, $colour ) ;
67
68       Draw an oval enclosed by the rectangle whose top left is ($x0,$y0) and
69       bottom right is ($x1,$y1) using a line colour of $colour.
70
71       rectangle()
72
73           $i->rectangle( $x0, $y0, $x1, $y1, $colour, $fill ) ;
74
75       Draw a rectangle whose top left is ($x0,$y0) and bottom right is
76       ($x1,$y1) using a line colour of $colour. If $fill is true then the
77       rectangle will be filled.
78
79       new()
80
81       Virtual - must be overridden.
82
83       Recommend that it at least supports "-file" (filename), "-width" and
84       "-height".
85
86       new_from_serialised()
87
88       Not implemented. Recommended for inheritors. Should accept a string
89       serialised using serialise() and return an object (reference).
90
91       serialise()
92
93       Not implemented. Recommended for inheritors. Should return a string
94       representation (ideally compressed).
95
96       get()
97
98           my $width = $i->get( -width ) ;
99           my( $hotx, $hoty ) = $i->get( -hotx, -hoty ) ;
100
101       Get any of the object's attributes. Multiple attributes may be
102       requested in a single call.
103
104       See "xy" get/set colours of the image itself.
105
106       set()
107
108       Virtual - must be overridden.
109
110       Set any of the object's attributes. Multiple attributes may be set in a
111       single call; some attributes are read-only.
112
113       See "xy" get/set colours of the image itself.
114
115       xy()
116
117       Virtual - must be overridden. Expected to provide the following func‐
118       tionality:
119
120           $i->xy( 4, 11, '#123454' ) ;    # Set the colour at point 4,11
121           my $v = $i->xy( 9, 17 ) ;       # Get the colour at point 9,17
122
123       Get/set colours using x, y coordinates; coordinates start at 0.
124
125       When called to set the colour the value returned is class specific;
126       when called to get the colour the value returned is the colour name,
127       e.g. 'blue' or '#f0f0f0', etc, e.g.
128
129           $colour = xy( $x, $y ) ;  # e.g. #123456
130           xy( $x, $y, $colour ) ;   # Return value is class specific
131
132       We don't normally pick up the return value when setting the colour.
133
134       load()
135
136       Virtual - must be overridden. Expected to provide the following func‐
137       tionality:
138
139           $i->load ;
140           $i->load( 'test.xpm' ) ;
141
142       Load the image whose name is given, or if none is given load the image
143       whose name is in the "-file" attribute.
144
145       save()
146
147       Virtual - must be overridden. Expected to provide the following func‐
148       tionality:
149
150           $i->save ;
151           $i->save( 'test.xpm' ) ;
152
153       Save the image using the name given, or if none is given save the image
154       using the name in the "-file" attribute. The image is saved in xpm for‐
155       mat.
156

CHANGES

158       2000/05/05
159
160       Added some basic drawing methods. Minor documentation changes.
161
162       2000/05/04
163
164       Created.
165

AUTHOR

167       Mark Summerfield. I can be contacted as <summer@perlpress.com> - please
168       include the word 'imagebase' in the subject line.
169
171       Copyright (c) Mark Summerfield 2000. All Rights Reserved.
172
173       This module may be used/distributed/modified under the LGPL.
174
175
176
177perl v5.8.8                       2000-05-26                           Base(3)
Impressum