Image sizing

People who are familiar with HTML markup often try to use the width attribute in an imagedata tag to scale their graphic. And often it works. But when they try to use other image attributes, they get strange results. Image sizing can be somewhat complex because there are many imagedata attributes that affect it. In addition to sizing the image itself, you can specify a viewport area, which is the space reserved for the image. If the viewport area is larger than the final image size, then there is white space around it. If the viewport area is smaller than the final image size, then the image is supposed to be clipped (but it doesn't happen in HTML output, may not happen in print output).

These are the attributes available in the imagedata element for sizing:

Imagedata scaling attributes

contentwidth, contentdepth

Specify the horizontal width or vertical height, respectively, of the image itself. You can specify a size using any of these units (with no space between the number and the unit):

px   Pixels (the default unit if none is specified)
pt   Points (1/72 of an inch)
cm   Centimeters
mm   Millimeters
pc   Picas (1/6 of an inch)
in   Inches
em   Ems (type size)
%    Percentage (of intrinsic image size)

If one of these attributes is specified, then the image is scaled proportionally to that size. You can stretch the image by specifying values for both attributes that differ from the original ratio of width to height of the image.

width, depth

Specify the horizontal width and vertical height, respectively, of the viewport area, not the graphic. It uses the same units as above, except percentage is taken to be of the available area (so 50% means half the available width after the current indent is subtracted). If these attributes are not specified, then the viewport is the whole page. These attributes will not affect the size of the image itself, with one exception. For backwards compatibility, if they are used without any other scaling attributes, the stylesheets will scale the image itself to the specified sizes. Think of it as a way of specifying the viewport area with the assumption that it should be filled up.

scale

A percentage scaling factor, but expressed without the percent sign. A value of 75 means to scale the graphic to 75% of its intrinsic size. It scales both width and height proportionally, so the image retains its original aspect ratio.

scalefit

If set to a value of 1, then the processor will scale the graphic proportionally to fit the allowed area. The image is scaled to fit the specified width or depth viewport dimension, whichever fills up first. If neither are specified, then it will scale to the available page width.

The definitive description of how these attributes are supposed to affect the output appears in the reference page for imagedata in DocBook: The Definitive Guide. In practice, some of the attributes are not fully supported by some processors.

Here is some guidance for using the scaling attributes.

Different sizes for HTML and FO output

You may find that you need to scale an image differently in HTML than in FO output. You can do this by creating nearly duplicate imageobject elements in a mediaobject. You can put different values for the scaling attributes in the imagedata element in each imageobject. Then you let the stylesheet select the appropriate imageobject for a given output. See the section “Selecting file formats” for more information.

If you just want to turn off scaling for HTML output, then that is even easier. If you set the stylesheet parameter ignore.image.scaling to a non-zero value, then all images in HTML output will appear in their intrinsic size. So you use the scaling attributes solely for FO output, and they will be ignored for HTML output.