Comparing images
MediaCompare for two versions of a picture in the page: side by side, swipe, onion skin or difference, at one scale; an author's image pair in Markdown, and MermaidCompare for a diagram.
When a picture changed, show its two versions as one MediaCompare, not as two images one
after the other. Both sides are drawn at one scale, so a picture that grew still looks bigger,
and the reader can lay one over the other to see exactly what moved.
The settings screenshot gained a field and its Save button moved. Side by side shows both whole; Swipe drags the newer over the older, Onion skin fades it in, and Difference blacks out every pixel that did not change, so only what changed is left. Click either picture to open the pair in the attachment viewer; with one side shown alone, click it and the viewer opens on that side alone too.
Which mode#
| The reader wants to | Mode |
|---|---|
| See both versions whole, or they differ in size or layout | Side by side |
| Find where a change begins and ends across the picture | Swipe |
| Judge a small shift, a nudged element or a recoloured one | Onion skin |
| Be sure nothing else changed | Difference |
The overlay modes line the two up at their top-left corner, as a screenshot is taken; a picture
drawn about its centre, as a diagram is, takes align="center". They wait until both sides have
a size, and a side that failed to load leaves side by side the only mode.
One side alone#
Each side's label is a toggle. Pressed, the comparison shows that side alone in the room the two shared, whichever mode is chosen; pressed again, or with a mode chosen, both come back. With one side alone, pressing the other's label trades the two in place, at one scale and in one position, so what changed jumps where it stands. It earns its place where there is no room for two: on a phone, side by side draws both too small, and one above the other too tall to read together.
Labels and sizes#
- Name the comparison with
title, as the viewer names the pair it opens: the file's name when both sides are one file, else both names with an arrow between them,before.png → after.png. The block and the viewer then agree on what the reader is looking at. - Tag each side with what tells the versions apart: a version (
v1,v2), a date, or Before and After when nothing else names them. A long tag is cut, and keeps its whole text as a tooltip. - Each label shows the side's natural size, and marks a dimension the two disagree on. Scaling hides a size change, so the label is where the reader learns of it.
backdrop="checker"shows transparency as the attachment viewer does, for screenshots and icons;backdrop="page"draws a picture on the page's own ground, for one made to sit on it.
Several on one page#
A page of comparisons is read one way: wrap them in one CompareModeProvider, and switching
any of them switches them all. Without it each keeps its own mode. Limit modes to what makes
sense for the pictures; a pair that can only sit side by side has no mode control at all.
In the viewer#
Detail a page cannot show is read in the attachment viewer. Below an AttachmentViewerProvider,
pass onOpen what useViewerCompare(pair, anchor) returns, the anchor being an element of the
comparison: the provider hands the viewer every comparison below it, in reading order, so paging
walks through them as the page does, whichever drew them. A nested provider pages its own apart,
for a surface whose comparisons are read on their own. With a lone AttachmentViewer and no
provider, hand it the page's comparisons yourself, as { compare, index } in its state, with
the solo that onOpen hears when a side was shown alone. Both versions share one zoom and one
position there, so a wheel or a drag over either moves both, and the mode bar under them is the
page's own when a CompareModeProvider holds them all. Its labels are toggles too, and trading a
side shown alone for the other keeps the zoom and the position.
A side drawn as a node rather than an image file, such as a diagram's SVG, zooms as vectors, side
by side being its only mode. The two sit left and right, to be read across, unless the viewer is
as narrow as a page on which the comparison stacks; there they stack too. Give such a side the
text it was drawn from as its source: the viewer's footer names its language and what it
draws, and offers each side's source to copy, as it offers an image's file to download.
Pairs an author writes#
In Markdown, an author compares two images by giving them a paragraph of their own with an arrow
between them,  →  (or ->). Register imagePairs with the
same resolver as markdownEmbeds, its useSource included, and that paragraph is one
MediaCompare, tagged by the two alts, or Before and After where an alt is only the file's name.
Anywhere else, in a sentence or with a third image, the images stay images: the author chose the
pair, so never pair images for them. Under an AttachmentViewerProvider a click opens the pair in the viewer, paging through
every comparison below the provider in reading order, the rest of the page's as well as the
document's own.
Diagrams#
A changed diagram is compared as a picture too: MermaidCompare draws both versions of a mermaid
source side by side, and colours what changed, the participant renamed or the node added, rather
than leaving the reader to spot it. Use it where the two sources are at hand, such as a review of a
document's versions; a source diff is one toggle away, and is what shows until both are drawn.
In the viewer, the footer names the diagrams' type as their sources spell it, and copies either
version's source. A diagram on its own opens in the viewer from its block's toolbar, to be zoomed
as an image is, with its type and its source to copy in the same place.