Name

ext:image-metadata — Return intrinsic properties of an image.

Function:
{http://docbook.org/extensions/xslt}image-metadata#1

Synopsis

ext:image-metadata($filename as xs:string) as map(*)

Description

This extension function returns a map of metadata properties about the image, including its intrinsic size: its width and height in pixels. If the size can be determined, the map returned will have a “width” key whose value is the width of the image and a “height” key whose value is the height of the image. Both sizes will be integer values.

This function uses the metadata-extractor library. The map may contain other properties as well.

  • If the media was successfully parsed with metadata-extractor, all of the properties identified by the extractor will be returned. Each property name will be converted to lowercase and spaces will be replaced with hyphens. (In other words, a property with the tag name “Palette Colour Count” will appear in the map with a key of “palette-colour-count”.)

    Property values that appear to be data/time values* will be converted to strings that are valid ISO 8601 date/time values. Any control characters that can’t appear in XML but that appear in a value will be replaced with Unicode references, \uxxxx. For example, a null byte will be replaced with \u0000.

  • If the media isn’t successfully parsed with metadata-extractor,

    • If it appears to be a PDF document, the function will search for the “MediaBox” or “CropBox” in the first 100 lines of the PDF. If either is found, its dimensions are used to calculate the width and height. If both are present, CropBox is preferred.

    • If it appears to be an SVG document, the function will search for width and height attributes on the root element. All of the attributes of the root element will be returned as properties, using Clark names.

If the width and height properties exist, they will always be integers. This means that if an image has a property with the name width or height and its value isn’t an integer, it will not be returned.

If the $debug parameter includes the token image-properties, the stylesheets will print every property returned in an xsl:message.