fedops blog

Privacy in Computing

Mon 02 May 2022

Quick Tip: the pqiv Image Viewer

Posted by fedops in Software   

Here's a quick pointer to a piece of software that I like a lot. It's called the Powerful Quick Image Viewer, or pqiv for short and it is - as the name suggests - a rather powerful image viewer that can be used from the command line (and thus in a scripted way as well).

In my digital image processing workflow (to be described in a future post) I have the need to review a large number of processed and exported images, preferably from the CLI. I have been using imv so far, which is fast, small, and light but is also really barebones. It is still a great choice especially for resource-constrained systems.

pqiv, helpfully pointed out to me by @mehrad@fosstodon.org, is a massive upgrade because besides being lightning fast it also has:

  • what's called "montage mode", a thumbnail preview which can be navigated easily to sort through a large number of images
  • key bindings that can be redefined via parameters and
  • an arbitrary number of external commands that can be bound to keys as well.

The source is available from the author Phillip Berndt's Github under the GPLv3 license if your distro-of-choice doesn't package it (Fedora doesn't though it's available via OpenSuse autobuilds). Installation is as simple as ./configure; make; sudo make install.

I've created what is essentially a one-liner bash script1 that collects my favorite parameter set like so:

#!/bin/sh
#
# display one or more images from the command line

pqiv --thumbnail-size=400x200 \
    --bind-key="<Right> { goto_file_relative(1) }" \
    --bind-key="<Left> { goto_file_relative(-1) }" \
    --bind-key="<Up> { montage_mode_enter() }" \
    --auto-montage-mode \
    --command-1="> exiftool $1 | grep -E 'Focal Length|Shutter Speed|Aperture|Create Date'; echo; echo" $@

You'll note pqiv makes use of a lot of special (to the shell) characters for the internal key and command names so use quotes carefully.

Top to bottom I'm setting the thumbnail size to fit inside a 400x200 pixel bounding box.

Then I'm redefining the cursor left and right keys to previous and next image respectively, and binding the cursor up key to enter montage (i.e. thumbnail) mode. Note that keybindings can be redefined when inside montage mode, these definitions are for normal mode only (montage mode already uses the cursor keys as expected).

Then with --auto-montage-mode we're entering montage mode automatically unless only a single image name is supplied on the command line.

And lastly the numeral "1" key is bound to an external command. It extracts some EXIF information from the picture that is currently displayed ($1 is populated with the image path and name by pqiv) and displays that in a pop-up window (triggered by the > symbol at the start of the command).

I'm really happy with pqiv - another example of how the command line can string together small Unix tools to arrive at a workflow that fits like a custom-made boot.


  1. this could totally be done as a shell alias as well, but I'm partial to wrapper scripts which are less efficient but more "obvious". YMMV.