Sizing and Transforming Images

A lot of image manipulation tasks consist of little more than resizing and cropping existing images. Table 3-3 shows the Image::Magick attributes that provide sizing and resolution information about an image. The page and density attributes may be set (with Set( )) to control the image size and resolution before reading in a PostScript file. The size attribute can be similarly set before creating images from raw data formats.

Table 3-3. Sizing and resolution attributes

Attribute

Read

Write

Description

base_columns

Yes

No

Returns an integer that is the width of the image before any transformations have been performed.

base_rows

Yes

No

Returns an integer that is the height of the image before any transformations have been performed.

columns

Yes

No

Returns the width (integer number of pixel columns) of the image.

Density

Yes

Yes

Use this attribute to set the vertical and horizontal resolution of an image. Set the density to a string in the form ‘horiz-density x vert-density’, e.g., ‘300x300’. It is most useful when reading a PostScript document.

The default is 72 dots per inch. Increase this to 144, for example, to render the PostScript to a larger sized image.

Geometry

Yes

No

Returns the bounds of the image. The geometry string is a convenient form that allows you to specify the width and height, or a region of an image with an offset. For example:

geometry=>'640x800'

is equivalent to:

width=>640, height=>800

To refer to a 20x20 region of pixels starting at coordinate (100,150), ...

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.