Filters and Effects

Another common task is applying filters to images to correct blurriness or to smooth out imperfections. A Sharpen( ) filter, for example, can be applied to an image after it is resized to clean up some of the blurring effects of resampling. Some of the methods described in this section, such as OilPaint( ), Whirl( ), or Implode( ), can also be used to add special effects to an image.

The Convolve( ) method is an all-purpose filter; many of the other filters utilize the Convolve( ) routine with built-in presets. If you know what a convolution kernel is, you may want to experiment with your own filters (or add to the built-in ones) with this function.

The Mogrify( ) method is also interesting. It acts as an alternative interface to the API, where you can specify filter or other method names with a text string. The MogrifyRegion( ) method lets you apply a filter or effect to a limited area of the image.

The two attributes in Table 3-8 may be read or set for use with certain filter methods.

Table 3-8. Filter and effect attributes

Attribute

Read

Write

Description

fuzz

Yes

Yes

The fuzz distance is used by ImageMagick functions that operate on all pixels of a certain color (e.g., the Floodfill drawing option or the Crop( ) method). If the fuzz distance is not 0, colors within the fuzz distance of each other are treated as the same color.

texture

Yes

Yes

The texture attribute assigns the filename of a texture to be tiled onto the image background.

The following filters and special effects ...

Get Perl Graphics Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.