3 Imager::Filters - Entire Image Filtering Operations
11 $img->filter(type=>'autolevels');
12 $img->filter(type=>'autolevels', lsat=>0.2);
13 $img->filter(type=>'turbnoise')
17 load_plugin("dynfilt/dyntest.so")
18 or die "unable to load plugin\n";
20 $img->filter(type=>'lin_stretch', a=>35, b=>200);
22 unload_plugin("dynfilt/dyntest.so")
23 or die "unable to load plugin\n";
28 Filters are operations that have similar calling interface.
30 =head2 Types of Filters
32 Here is a list of the filters that are always avaliable in Imager.
33 This list can be obtained by running the C<filterlist.perl> script
34 that comes with the module source.
36 Filter Arguments Default value
41 bumpmap bump lightx lighty
73 gradgen xo yo colors dist
93 unsharpmask stddev 2.0
101 All parameters must have some value but if a parameter has a default
102 value it may be omitted when calling the filter function.
104 A reference of the filters follows:
110 scales the value of each channel so that the values in the image will
111 cover the whole possible range for the channel. I<lsat> and I<usat>
112 truncate the range by the specified fraction at the top and bottom of
113 the range respectivly.
117 uses the channel I<elevation> image I<bump> as a bumpmap on your
118 image, with the light at (I<lightx>, I<lightty>), with a shadow length
121 =item bumpmap_complex
123 uses the channel I<channel> image I<bump> as a bumpmap on your image.
124 If Lz<0 the three L parameters are considered to be the direction of
125 the light. If Lz>0 the L parameters are considered to be the light
126 position. I<Ia> is the ambient colour, I<Il> is the light colour,
127 I<Is> is the color of specular highlights. I<cd> is the diffuse
128 coefficient and I<cs> is the specular coefficient. I<n> is the
129 shininess of the surface.
133 scales each channel by I<intensity>. Values of I<intensity> < 1.0
134 will reduce the contrast.
138 performs 2 1-dimensional convolutions on the image using the values
139 from I<coef>. I<coef> should be have an odd length.
143 renders a fountain fill, similar to the gradient tool in most paint
144 software. The default fill is a linear fill from opaque black to
145 opaque white. The points A(xa, ya) and B(xb, yb) control the way the
146 fill is performed, depending on the ftype parameter:
152 the fill ramps from A through to B.
156 the fill ramps in both directions from A, where AB defines the length
161 A is the center of a circle, and B is a point on it's circumference.
162 The fill ramps from the center out to the circumference.
166 A is the center of a square and B is the center of one of it's sides.
167 This can be used to rotate the square. The fill ramps out to the
172 A is the centre of a circle and B is a point on it's circumference. B
173 marks the 0 and 360 point on the circle, with the fill ramping
178 A is the center of a circle and B is a point on it's circumference. B
179 marks the 0 and point on the circle, with the fill ramping in both
180 directions to meet opposite.
184 The I<repeat> option controls how the fill is repeated for some
185 I<ftype>s after it leaves the AB range:
191 no repeats, points outside of each range are treated as if they were
192 on the extreme end of that range.
196 the fill simply repeats in the positive direction
200 the fill repeats in reverse and then forward and so on, in the
205 the fill repeats in both the positive and negative directions (only
206 meaningful for a linear fill).
210 as for triangle, but in the negative direction too (only meaningful
215 By default the fill simply overwrites the whole image (unless you have
216 parts of the range 0 through 1 that aren't covered by a segment), if
217 any segments of your fill have any transparency, you can set the
218 I<combine> option to 'normal' to have the fill combined with the
219 existing pixels. See the description of I<combine> in L<Imager/Fill>.
221 If your fill has sharp edges, for example between steps if you use
222 repeat set to 'triangle', you may see some aliased or ragged edges.
223 You can enable super-sampling which will take extra samples within the
224 pixel in an attempt anti-alias the fill.
226 The possible values for the super_sample option are:
232 no super-sampling is done
236 a square grid of points are sampled. The number of points sampled is
237 the square of ceil(0.5 + sqrt(ssample_param)).
241 a random set of points within the pixel are sampled. This looks
242 pretty bad for low ssample_param values.
246 the points on the radius of a circle within the pixel are sampled.
247 This seems to produce the best results, but is fairly slow (for now).
251 You can control the level of sampling by setting the ssample_param
252 option. This is roughly the number of points sampled, but depends on
253 the type of sampling.
255 The segments option is an arrayref of segments. You really should use
256 the Imager::Fountain class to build your fountain fill. Each segment
257 is an array ref containing:
263 a floating point number between 0 and 1, the start of the range of fill parameters covered by this segment.
267 a floating point number between start and end which can be used to
268 push the color range towards one end of the segment.
272 a floating point number between 0 and 1, the end of the range of fill
273 parameters covered by this segment. This should be greater than
280 The colors at each end of the segment. These can be either
281 Imager::Color or Imager::Color::Float objects.
285 The type of segment, this controls the way the fill parameter varies
286 over the segment. 0 for linear, 1 for curved (unimplemented), 2 for
287 sine, 3 for sphere increasing, 4 for sphere decreasing.
291 The way the color varies within the segment, 0 for simple RGB, 1 for
292 hue increasing and 2 for hue decreasing.
296 Don't forget to use Imager::Fountain instead of building your own.
297 Really. It even loads GIMP gradient files.
301 performs a gaussian blur of the image, using I<stddev> as the standard
302 deviation of the curve used to combine pixels, larger values give
303 bigger blurs. For a definition of Gaussian Blur, see:
305 http://www.maths.abdn.ac.uk/~igc/tch/mx4002/notes/node99.html
309 renders a gradient, with the given I<colors> at the corresponding
310 points (x,y) in I<xo> and I<yo>. You can specify the way distance is
311 measured for color blendeing by setting I<dist> to 0 for Euclidean, 1
312 for Euclidean squared, and 2 for Manhattan distance.
316 inverts the image, black to white, white to black. All channels are
317 inverted, including the alpha channel if any.
321 produces averaged tiles of the given I<size>.
325 adds noise of the given I<amount> to the image. If I<subtype> is
326 zero, the noise is even to each channel, otherwise noise is added to
327 each channel independently.
331 renders radiant Perlin turbulent noise. The centre of the noise is at
332 (I<xo>, I<yo>), I<ascale> controls the angular scale of the noise ,
333 and I<rscale> the radial scale, higher numbers give more detail.
337 alters the image to have only I<levels> distinct level in each
342 renders Perlin turbulent noise. (I<xo>, I<yo>) controls the origin of
343 the noise, and I<scale> the scale of the noise, with lower numbers
348 performs an unsharp mask on the image. This is the result of
349 subtracting a gaussian blurred version of the image from the original.
350 I<stddev> controls the stddev parameter of the gaussian blur. Each
351 output pixel is: in + I<scale> * (in - blurred).
355 applies I<wmark> as a watermark on the image with strength I<pixdiff>,
356 with an origin at (I<tx>, I<ty>)
360 A demonstration of most of the filters can be found at:
362 http://www.develop-help.com/imager/filters.html
364 (This is a slow link.)
369 It is possible to add filters to the module without recompiling the
370 module itself. This is done by using DSOs (Dynamic shared object)
371 avaliable on most systems. This way you can maintain our own filters
372 and not have to get me to add it, or worse patch every new version of
373 the Module. Modules can be loaded AND UNLOADED at runtime. This
374 means that you can have a server/daemon thingy that can do something
377 load_plugin("dynfilt/dyntest.so")
378 or die "unable to load plugin\n";
380 $img->filter(type=>'lin_stretch', a=>35, b=>200);
382 unload_plugin("dynfilt/dyntest.so")
383 or die "unable to load plugin\n";
385 Someone decides that the filter is not working as it should -
386 dyntest.c modified and recompiled.
388 load_plugin("dynfilt/dyntest.so")
389 or die "unable to load plugin\n";
393 An example plugin comes with the module - Please send feedback to
394 addi@umich.edu if you test this.
396 Note: This seems to test ok on the following systems:
397 Linux, Solaris, HPUX, OpenBSD, FreeBSD, TRU64/OSF1, AIX.
398 If you test this on other systems please let me know.