1Base(3) User Contributed Perl Documentation Base(3)
2
3
4
6 Image::Base - base class for loading, manipulating and saving images.
7
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
41 new_from_image()
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
46 Note that the above will only work if you've installed Image::Xbm and
47 Image::Xpm, but will work correctly for any image object that inherits
48 from Image::Base and respects its API.
49
50 You can use this method to transform an image to another image of the
51 same type 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 line()
58 $i->line( $x0, $y0, $x1, $y1, $colour ) ;
59
60 Draw a line from point ($x0,$y0) to point ($x1,$y1) in colour $colour.
61
62 ellipse()
63 $i->ellipse( $x0, $y0, $x1, $y1, $colour ) ;
64
65 Draw an oval enclosed by the rectangle whose top left is ($x0,$y0) and
66 bottom right is ($x1,$y1) using a line colour of $colour.
67
68 rectangle()
69 $i->rectangle( $x0, $y0, $x1, $y1, $colour, $fill ) ;
70
71 Draw a rectangle whose top left is ($x0,$y0) and bottom right is
72 ($x1,$y1) using a line colour of $colour. If $fill is true then the
73 rectangle will be filled.
74
75 new()
76 Virtual - must be overridden.
77
78 Recommend that it at least supports "-file" (filename), "-width" and
79 "-height".
80
81 new_from_serialised()
82 Not implemented. Recommended for inheritors. Should accept a string
83 serialised using serialise() and return an object (reference).
84
85 serialise()
86 Not implemented. Recommended for inheritors. Should return a string
87 representation (ideally compressed).
88
89 get()
90 my $width = $i->get( -width ) ;
91 my( $hotx, $hoty ) = $i->get( -hotx, -hoty ) ;
92
93 Get any of the object's attributes. Multiple attributes may be
94 requested in a single call.
95
96 See "xy" get/set colours of the image itself.
97
98 set()
99 Virtual - must be overridden.
100
101 Set any of the object's attributes. Multiple attributes may be set in a
102 single call; some attributes are read-only.
103
104 See "xy" get/set colours of the image itself.
105
106 xy()
107 Virtual - must be overridden. Expected to provide the following
108 functionality:
109
110 $i->xy( 4, 11, '#123454' ) ; # Set the colour at point 4,11
111 my $v = $i->xy( 9, 17 ) ; # Get the colour at point 9,17
112
113 Get/set colours using x, y coordinates; coordinates start at 0.
114
115 When called to set the colour the value returned is class specific;
116 when called to get the colour the value returned is the colour name,
117 e.g. 'blue' or '#f0f0f0', etc, e.g.
118
119 $colour = xy( $x, $y ) ; # e.g. #123456
120 xy( $x, $y, $colour ) ; # Return value is class specific
121
122 We don't normally pick up the return value when setting the colour.
123
124 load()
125 Virtual - must be overridden. Expected to provide the following
126 functionality:
127
128 $i->load ;
129 $i->load( 'test.xpm' ) ;
130
131 Load the image whose name is given, or if none is given load the image
132 whose name is in the "-file" attribute.
133
134 save()
135 Virtual - must be overridden. Expected to provide the following
136 functionality:
137
138 $i->save ;
139 $i->save( 'test.xpm' ) ;
140
141 Save the image using the name given, or if none is given save the image
142 using the name in the "-file" attribute. The image is saved in xpm
143 format.
144
146 2000/05/05
147
148 Added some basic drawing methods. Minor documentation changes.
149
150 2000/05/04
151
152 Created.
153
155 Mark Summerfield. I can be contacted as <summer@perlpress.com> - please
156 include the word 'imagebase' in the subject line.
157
159 Copyright (c) Mark Summerfield 2000. All Rights Reserved.
160
161 This module may be used/distributed/modified under the LGPL.
162
163
164
165perl v5.16.3 2000-05-26 Base(3)