Flipper and Swapper

HTML tools for image display

Presenting a sequence of images from a thumbnail gallery is popular on the Web —and justly so. The interface (gallery itself) can be easily customized; it is also simple and self-explanatory to the user.

This implementation is also simple to program: each image requires just one img=... element and one a href=... link. No JavaScript and no browser compatibility issues.

There is one disadvantage to this approach, though: to go from one full-screen image display to another, we have first to return to the thumbnail page.

Quite often this is just a minor inconvenience or a secondary aesthetic issue. Sometimes, however, we would prefer to replace one image displayed with another, without anything in-between interrupting the continuity. Presentation concerns aside, this is extremely helpful in critical comparisons of similar images, as it allows to catch very subtle differences, like those in sharpness, noise, or tonality.

I will skip the issue of the so-called image galleries on so-called social media sites. Visit some of those and you will understand why. Besides, I consider these sites to be a symptom of the sad state of affairs on the Internet. Giving out machine guns with unlimited ammo supply to a bunch of monkeys may also seem a good idea at first.

Last year I decided to write my own tools for providing the missing functionality. This is a detailed description; I would like to hope it will benefit two groups of Readers:

  • Frequent visitors to wrotniak.net (both of them), who will be now able to use Swapper and Flipper to their full potential (no big deal, these things are self-explanatory or almost so);
  • Those who do their own Web authoring and may find a good use for utilities to display sequences of images — from critical flip-over comparisons to slide shows.
Developers: Technical information and that related to using the tools from HTML code is shown in this format, and with the Developers header. A more casual Reader will be given an option to skip over those parts.

The Swapper

The Swapper is used to show sequences of images (shrunk to fit, if needed) in full-screen (or rather full-window) display. The starting image is selected by the calling page.

New in Version 1.2: The sequence can now be up to 99 images long (not just 10).

New in Version 1.1: The calling page may also activate the panning (or full-height) display mode. This works only with images of an aspect ratio wider than that of your browser window (otherwise it is just ignored). In this mode, if the image height does not fit into the window, the image is shrunk so that it does. The viewer can see a full-height fragment of the image, using the keyboard to scroll left and right. Both display modes can be toggled.

Once the Swapper link is activated and the full-window image comes up, the user has a few rudimentary keyboard options accessible:

  • and — move between images (regular mode) or scroll left and right (panning mode),
  • and — move between images (either mode);
  • 1 ... 9 9— jump directly to image 1...99, if applicable;
  • V — toggle the panning mode, if enabled; Space and Enter can also be used for that;
  • C — toggle captions;
  • H or F1 for help.

Also, all major browsers (current versions) support F11 for toggling the full-screen (kiosk) mode, and Backspace for return to the calling page.

Let us see a real, working example of a Swapper used to compare image quality of a camera at three different ISO settings. This whole-frame thumbnail provides a link to the Swapper.

The panning mode is not activated in this example, as it does not make sense for the 4:3 image aspect ratio.

Note, that while Swapper will handle a sequence of up to 99 images, it is most practical with just two or three. For more, while you can still use numeric keys to make a single transition between any two, you have to remember which is which. This can not be helped. For larger image sets I would rather recommend the Flipper anyway.

Olympus E-M1 II, MZD 75/1.8 at F/1.8

Three panoramas, shown in one Swapper

Now, another example, this time a mini-gallery of three panoramic images. While most often I'm using this mode of Swapper to show a single panorama, it will handle sequences just fine, too.

A minor detail: the built-in help shows only the options applicable to a given usage of the Swapper in the page code.

That's all an end user has to know; you didn't really need these explanations to use the Swapper. Just a formality. Unless you want to know how to use the Swapper in your own code, feel free to jump over to the Flipper section.

Developers

Swapper is a single HTML file, containing also all necessary JavaSceipt code and CSS definitions, and therefore referring to no external resources. The file, named _swap.html, can be placed anywhere in your HTML file tree (whether on the server or locally on your development machine), best at its root.

The link consists of the Swapper file name followed by arguments, specifying images to be included, which one to start from, and (optionally) image captions. This may become quite long, but it can't be helped: all this information has to be somehow passed to the Swapper.

A simple invocation may, for example, look like this:

<a href=../_swap.html?f1=iso200.jpg&f2=iso400.jpg&f3=iso800.jpg>

This specifies the location of Swapper as one level up from the current file. Three image files will be shown, all expected to be found in the same folder where the Snapper is, or their names have to include relative path(s) from that folder

The argument list must be preceded by a question mark, '?', and the individual arguments are separated with ampersands, '&'. Instead of spaces inside arguments, use plus signs; they will be replaced. (Using spaces in filenames is asking for a disaster, anyway.) All this is a part of the standard HTML syntax.

This example was very simple, using just a few of the arguments Swapper allows. Here is the full list.

Argument Meaning Example Explanation
i Ordinal number of the file displayed i=1 Numbering starts from 1. If not present, 1 is assumed.
f1..f99 File IDs or names. f2=128 The full name of file with partial name ff will be pre+ff+suf
or, in this example
photo/_img/smp/em12/iso-12800.s.jpg
pre Common file name prefix pre=photo/_img/smp/em12/iso-
suf Common file name suffix 00.s.jpg
c1..c0 Captions c2=ISO+12800,+no+Noise+Filter If not defined, full file name is used; use + for spaces
hide Hide text info hide=1 If non-zero, logo and caption display will be suppressed
pan Enable panning mode pan=1 If non-zero, panning mode will be enabled
The actual HTML code attached to the thumbnails above is shown here
<a href="../../_swap.html?pre=photo/bytes/_img/swap-iso/em1.2-&suf=_cr.jpg &f1=00200&f2=01600&f3=25600&c1=ISO+200&c2=ISO+1600&c3=ISO+25600"> <img src="_img/swap-iso/em1.2-00200.t.jpg"> </a>

and

<a href="../../_swap.html?pre=photo/m43/_img/sunset/&suf=.s.jpg&pan=1&f1=7332-c&f2=pp2&f3=180609-9131"> <img src="../m43/_img/sunset/7332-c.t.jpg"> </a>

The whole <a> tag preceding <img> must be entered as a single line (with no spaces added), or else. Also, note the plus signs substituting for spaces in caption arguments of the first example.

The Swapper logo, superimposed on thumbnails, is purely cosmetic, generated by the HTML code of the page, and unrelated to the Swapper itself; just ignore it.

The Flipper

The Flipper is like a Swapper on steroids. At a price. It will do most of what Swapper does, and then some:

  1. Instantaneous swapping (flipping?) of any image with a preselected anchor;
  2. Slide shows: sequential or random; adjustable speed;
  3. Optional, on-screen, mouse-driven GUI on demand.

One feature of its sibling the Flipper is missing, is the panning mode.

In earlier versions, the number of images was limited by the available GUI space. Not any longer: the list will now scroll if necessary.

Again, a real-life example, introduced elsewhere on wrotniak.net — showing various versions of image postprocessing in color or monochrome.

Run this example and press U for the on-screen interface. The current image is marked red; When you start moving around with mouse, arrow keys, or buttons, a yellow label will appear. Pressing F or clicking Flip will flip (exchange) these two.

Usually it is the previous viewed image: the "flipping partner" of the current one. Press L or click Lock, however, to lock the current image as a new yellow anchor, and it will stay as such until another Lock is performed, or a Flip done; in both cases we get a new locked anchor.

The locked status is denoted by dark-green label background. To remove that status altogether, move to that image (so that it is shown as red on green) and press L again.

Olympus E-M1, MZD 12-40/2.8 @ 40mm

This may sound convoluted, but it really isn't. You should get the hang of it in a minute or two of navigating the image sequence.

An extra feature thrown in into Flipper is the slide show (preset or random order); not useful in image comparison but nice to have just for browsing/viewing.

Here is a full listing of the keyboard and button interface:

  •  ,  or for moving between images;
  • 1 ... 9 9 for jumping directly to images 1...99, if applicable;
  • F or Flip for flipping back and forth between two images;
  • L or Lock for locking the "flipping partner" image;
  • A or Auto to start or stop a slide show;
  • R or Rand to start or stop a slide show;
  • - + to adjust the slide show timing (1 to 22 seconds);
  • C to toggle captions;
  • H or F1 for help.

Most importantly, every image has its radio button in the screen interface, which allows for non-sequential access (if that interface is active, of course). Like in the Swapper, the F11 and Backspace keys retain their customary browser functions.

Now, you may want to ask me about the price I've mentioned, for using the Flipper instead of its little sibling.

For the end user, who is just accessing the Web pages, this price is negligible: a small increase in complexity of the user interface. More: the Reader who is not using the Flipper's extra features will not notice any changes.

For the developer, who is authoring the pages using Flipper or Swapper, the price is still not high: for each sequence of images a tiny HTML page has to be written, listing the files to show and some display options. (Well, if you want the options, you have to specify them somehow.) I will discuss that further down, in a developer's section, and if you really don't need to know the internals, feel free to jump over it.

Developers

Now, for every set of images to be displayed we need another Flipper HTML file, with most of its contents being the list of image files to be displayed. Another part specifies some run parameters. The third, smallest group of lines (just a dozen or so) are some obligatory tags, which really do nothing but are required.

That is right! This is actually an HTML file without any working HTML code! All work is done by a separate JavaScript file (_flip.js), which the HTML only refers to. In a similar fashion, all style information sits in a separate Cascading Style Sheet file _flip.css), just one, shared by all Flipper pages on a Web site.

The Flipper HTML file can have, basically, any name following your server rules. I'm always using a double extension, .f.html for these files, as this makes them easy to find among all the files I'm hosting. Thus, for example, the file I'm using in the section above is named psp-badlands.f.html — I don't need to open it to know that it is a Flipper HTML.

Here is another example of linking to a Flipper, just for fun of it. This one is an outstanding piece of street art from San Juan, Puerto Rico, 2011 (I hope the original still exists!).

A link to Flipper uses just the file name; no obligatory arguments. The optional id is the text ID of the image to be first shown on load. If not specified, it will default to the first image in the list.

Therefore for this thumbnail, two forms of link may be used, both very simple:

<a href=flip-example.f.html>whatever</a> <a href=flip-example.f.html?id=chr>whatever</a>

Olympus E-30, MZD 12-60/2.8-4.0 @51 mm

Now the .html file. I'm including one in the package, to be used as a template to modify. It is shown and explained below. You will have to modify it so that it specifies the images you want to display. Actually, no HTML, CSS, or JavaScript coding skills are required; just keep the existing syntax intact.

The lines of the file are color-coded in the table below:

  • No color: don't remove or modify;
  • Green: optional, can be modified to tweak the show to your preferences;
  • Blue: will probably need to be changed because of a different file location;
  • Red: must be modified to specify images to show.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
Don't touch these lines; just ignore them.
<link rel="shortcut icon" href="../../fav.js.ico">
Remove this line if your site does not use favicons; otherwise modify as needed.
<style type="text/css">
@import url("../../_flip.css");
</style>
The path will usually need an adjustment, depending on where you placed this Flipper file and the shared _flip.css — I keep the latter in my root www directory.
<script type="text/javascript">
Leave this alone, too.
var _tit = "PSP EFFECTS";
Title to be used for the window and in screen GUI.
var _pre = "_img/psp-fx/110404-7401a-";
var _suf = ".s.jpg";
Prefix and suffix common to all file names in this particular Flipper. See below for more.
var _oo = [
[ "0", "Original","Original in-camera JPEG"],
[ "1st", "One Step Fix", "" ],
[ "ltm", "Local Tone Map", "" ],
[ "pos", "Posterization", "" ],
[ "chr", "Chromium", "" ],
[ "spl", "Soft Plastic", "" ],
[ "hp", "High Pass", "" ],
[ "ngn", "Neon Glow", "" ],
[ "sol", "Solarization", "" ],
[ "cfo", "Color Foil", "" ]
];
Each row of this table describes one image file: three text items within square brackets. These items are:
  • File ID, which defines the file name as prefix+ID+suffix. For example, the last file name is _img/ -fx/110404-7401a-cfo.s.jpg
  • Label, a short mnemonic which will be used in the on-screen GUI. If the label is empty, a full file name (see above) will be used.
  • Caption, which will be shown with the image (if the option s active). If the caption is empty (like most in this example), Label will be used.
var _font_size = 10;
Font size (pt) for the GUI image list.
var _hide_ui = 1;
Hide the GUI at page load? (0/1, see above); also suppress logo display (2)
var _preload = 1;
Preload images on start? (0/1, see above) Some browsers may ignore this request.
</script>
<script type="text/javascript" src="../../_flip.js">
</script>
This is the JavaScript file which does the whole work. You may have to modify the path as per your file locations.
</head>
<body id=BODY></body>
</html>
Another piece not to be modified.

I think this is all you need to start using the Flipper in your own Web development. All files you need (including the example/template discussed above) are packaged in the download archive, accessible from the download section.

Browser Compatibility

I've tested the Swapper and the Flipper on current (September, 2018) versions of all "major" browsers under Windows 10: Chrome, Opera, and Vivaldi (all sharing the same engine with exemplary standard conformance), but also on Firefox, Edge, and Internet Explorer. The worst I could find was "blinking" at image transition (in spite of a preload request upon start); it is a minor issue and Opera seems to be handling it best.

I haven't done any testing on Mac computers. Based on my past experiences, I wouldn't expect problems on Chrome or Opera, but I would on Safari, which in the past used to be notoriously non-conformant to HTML standards.

Android? Forget about it, at least for a while. A long one. First, I would have to become familiar with programming the touch-screen interface; second, Android browsers tend to render Web pages the way they think is right, often quite different from what the developer coded.

Downloads

Swapperswapper.zip, including just _swap.html, which is all you need;

Version 1.25 — cleanup

Version 1.22 — Up and Down keys used ([<] and [>] still supported, undocumented, for compatibility)

Version 1.20 — handles up to 99 images.

Version 1.15 — better compatibility with Microsoft browsers.

Version 1.13 — cosmetic improvements.

Version 1.10 introduces the panning mode for panoramas, adds context sensitivity to Help, plus some cosmetic improvements.

Version 1.04 removes a visible outline of a hidden text field.

Version 1.03 fixes the Backspace key in Chrome.

 Flipper flipper.zip, including _flip.js, _flip.css and the flip-example.f.html template to convert into your own HTML.

Version 2.00 — some arguments now optional; no legacy support for _id[]

Version 1.25 — cleanup

Version 1.22 — see Swapper 1.22

Version 1.20 — handles up to 99 images. Changed keys for slide show timing.

Version 1.08 — better compatibility with Microsoft browsers; hiding scrollbar for panning.

Version 1.07 adds an option to suppress the logo display at startup (_hide=2).

Version 1.05 adds scrolling to image list; cosmetic improvements.

Version 1.03 improves help layout in small windows and restores the Backspace key functionality in Chrome.

`

What next?

By now (June, 2019), I've been using the Flipper for more than a year, cleaning, refining and enhancing it, and the Swapper for five months. Both seem to behave. Still, I would like to add some features to both (but stop short of the proverbial kitchen sink).

A quite ambitious project would be adding variable image scaling, preserving scale and position when moving between images. I'm not sure how easy this may be, but I would like to try. This would be great for critical comparison of image samples.


Home: wrotniak.net | Search this site | Change font size

Photo News | The Gallery


Posted 2018/05/18; last updated 2020/06/01 Copyright © 2018 by J. Andrzej Wrotniak