Images

There are two AsciiDoc image macro types, block and inline. As with all macros, the block and inline forms differ by the number of colons that follow the macro name. The block form uses two colons (::), whereas the inline form only uses one (:).

Block image macro

A block image is displayed as a discrete element, i.e., on its own line, in a document. A block image is designated by image macro name and followed by two colons (::) It’s preceded by an empty line, entered on a line by itself, and then followed by an empty line.

Example 1. Block image macro
Content in document.

image::sunset.jpg[] (1) (2)

Content in document
1 To insert a block image, type the image macro name directly followed by two colons (::).
2 After the colons, enter the image file target. Type a pair of square brackets ([]) directly after the target to complete the macro.

The result of Example 1 is displayed below.

sunset

The target is required. The target may be a relative path or a URL. How the target is interpreted depends on the processor settings and/or output format. If the converter generates output that references the image, the path must be relative to the published document. If the converter embeds the image in the output document (e.g., inline SVG, data-uri is set, converting to PDF directly), the target must be resolvable at convert time. In the latter case, a URL will only be resolved if the security settings on the processor allows it (e.g., allow-uri-read).

The target may contain space characters. In the HTML output, these spaces will be URL encoded (i.e., %20).

You can specify a comma-separated list of optional attributes inside the square brackets or leave them empty. If you want to specify alt text, enter it inside the square brackets.

Example 2. Block image macro with alt text
image::sunset.jpg[Sunset]

If the alt text contains a comma, you must enclose the alt text in double quotes. The double quote enclosure effectively escapes the comma from being interpreted as an attribute separator.

Example 3. Block image macro with alt text that contains a comma
image::sunset.jpg["Mesa Verde Sunset, by JAVH"]
Although you could enclose the alt text in single quotes to escape the comma, doing so implicitly enables substitutions. Unless you need substitutions to be applied to the alt text, prefer using double quotes as the enclosure.

You can also give the image an ID, title, set its dimensions and make it a link.

Example 4. Block image macro with attribute list
.A mountain sunset (1)
[#img-sunset,link=https://www.flickr.com/photos/javh/5448336655] (2)
image::sunset.jpg[Sunset,200,100] (3) (4)
1 Defines the title of the block image, which gets displayed underneath the image when rendered.
2 Assigns an ID to the block and makes the image a link. The link attribute can also be defined inside the attribute list of the block macro.
3 The first positional attribute, Sunset, is the image’s alt text.
4 The second and third positional attributes define the width and height, respectively.

The result of Example 4 is displayed below.

Sunset
Figure 1. A mountain sunset

Figure caption label

When a title is defined on a block image, the image title will be prefixed by a caption label (Figure) and numbered automatically. To turn off figure caption labels and numbers, unset the figure-caption attribute in the document header.

= Document Title
:figure-caption!:

Inline image macro

An inline image is displayed in the flow of another element, such as a paragraph or sidebar block. The inline image macro is almost identical to the block image macro, except its macro name is followed by a single colon (:).

Example 5. Inline image macro
Click image:play.png[] to get the party started. (1)

Click image:pause.png[title="Pause"] when you need a break. (2)
1 In the flow of an element, enter the macro name and a single colon (image:), followed by the image target. Complete the macro with a pair of square brackets ([]).
2 You can specify a comma-separated list of attributes inside the square brackets or leave them empty.

The result of Example 5 is displayed below.

Click play to get the party started.

Click pause when you need a break.

The target is required. The target may be a relative path or a URL. How the target is interpreted depends on the processor settings and/or output format. If the converter generates output that references the image, the path must be relative to the published document. If the converter embeds the image in the output document (e.g., inline SVG, data-uri is set, converting to PDF directly), the target must be resolvable at convert time. In the latter case, a URL will only be resolved if the security settings on the processor allows it (e.g., allow-uri-read).

The target may contain space characters. In the HTML output, these spaces will be URL encoded (i.e., %20).

For inline images, the optional title is displayed as a tooltip.