XML technologies / DocBook / Block elements / Graphics / Controlling image size

(Excerpt from "DocBook-XML: Media-neutral and platform-independent publishing" by Thomas Schraitle)

Correctly applying image height and width attribute values and understanding how they interact with other attributes is a frequent source of frustration.

The element imagedata has several attributes controlling how different rectangles interact:

Viewport area ( viewport area)

This rectangle defines the available area in which the image is placed. Defining a viewport area of 5 cm × 6 cm reserves that space for the image, regardless of other dimensions.

Content area ( content area)

This rectangle defines the dimensions of the displayed image, independently of its actual size. DocBook provides three mutually exclusive ways to specify the content area: directly, through a scaling factor, or by making it the same size as the viewport area.

Intrinsic image size ( intrinsic size)

The actual dimensions of the image

If the content area is larger than the viewport area, the result depends on the publishing system. DocBook defines no mechanism for this case. A publishing system may clip the image, allow it to overflow, report an error, or combine these options.

Table: Image attributes

Area

Attributes

Viewport area

depth and width

Content area

contentdepth and contentwidth

Scaling

scale or through scalefit

Alignment

Horizontal and vertical alignment of the content area within the viewport area;
align and valign

The following examples consider only the element imagedata. They require DocBook version 4.2 or later. The image file test.png is assumed to measure 2 cm × 2 cm.

Table: Viewport and content areas of an image (2 cm × 2 cm)

Image

Description

Viewport and content areas of an image (2 cm × 2 cm)

If nothing is specified, the content area has the same size as the image. The viewport size depends on the implementation. The value of the attribute scalefit is irrelevant in this case:

<imagedata fileref="test.png"/>

Viewport and content areas of an image (2 cm × 2 cm)

Produces an image 4 cm wide. Its height is scaled proportionally (the value of scalefit defaults to 1 in this case):

<imagedata fileref="test.png" width="4cm"/>

Viewport and content areas of an image (2 cm × 2 cm)

Produces a content area matching the image dimensions. However, the attribute scalefit with the value 0 keeps the image at its original size. The attributes align and valign let you align the image horizontally and vertically within the viewport. If nothing is specified, alignment depends on the implementation. Usually, the upper-left corner is chosen.

<imagedata fileref="test.png" width="4cm" scalefit="0"/>

Viewport and content areas of an image (2 cm × 2 cm)

If a scaling factor is specified, the intrinsic image size is scaled uniformly to fit a content area. The viewport size depends on the implementation.

<imagedata fileref="test.png" scale="200" />

Viewport and content areas of an image (2 cm × 2 cm)

If both viewport and content areas are specified, the image is scaled to the content area, possibly non-uniformly. The content area is displayed within the specified viewport:

<imagedata fileref="test.png" width="4cm" depth="4cm" content-width="3cm" />

Some presentations are difficult to implement, depending on the target format. (X)HTML often requires compromises, and some attribute combinations may require extension functions from your XSLT processor.

  

back to top