CLI Magic: Feh for image viewing

7451

Author: Michael Stutz

Too many Linux image viewers are tinged with little annoyances — they take too long to load, are slow to redraw the display, have limited format support, sport inconvenient controls — so when you want to settle on one, inevitably there’s something to make you utter feh! in general discontent. Good call — feh is the name of a speedy little viewer that packs in a surprising number of features for its size.

Feh takes as arguments the names of image files you want to view. You can also give directory names, and feh attempts to load all the files in that directory; the -r option recurses through all subdirectories. Viewing all image files in the /usr/local/photos directory tree, for instance, is done like this:

$ feh -r /usr/local/photos

If you specify more than one image, only the first will immediately display; type n (or the spacebar) to move to the next and p to move to the previous. The Home and End keys bring you to the first and last images in the argument list. To quit viewing and exit, type q.

You can put a list of images to load in a file, with full or relative pathnames, and specify the file with the -f option; the -z option will randomize the display order. The images can be advanced automatically by giving a delay, in seconds, as an argument to the -D option. This slideshow mode is the default mode; feh is a modal viewer, so its options and controls differ depending on the mode. Its other modes are discussed below.

You can also view images over any http or ftp URL by giving the URL as an argument, like so:

$ feh http://www.glerl.noaa.gov/pubs/photogallery/Scenic/images/0534.jpg

If you have a file that contains a list of image URLs, you can have feh display them in a random-order slideshow, with a delay of 30 seconds each, with this command:

$ cat image-urls | xargs feh -z -D30

Mouse controls

What’s really special about feh is the way it pans and zooms images — it’s impressively fast and fluid.

If an image is too large to fit the display, click the left mouse button and move the pointer to pan around the image.

To resize the view, click the middle button and move the pointer toward the left or right to shrink or grow the image.

You can click and release the left mouse button once to move to the next image. A few viewing effects are also available: hold down the Ctrl key and press the left mouse button: when you do so, moving the pointer to the left blurs the image, while moving to the right sharpens it. With Ctrl and the middle mouse button pressed, you can move the pointer to spin the image around its center.

When viewing an image, click the right mouse button to display feh’s menus.

Menus, edits, and modes

Feh is strictly an image viewer — it doesn’t attempt to be an editor at all, but a couple of the most common editing commands are available on the menu: rotation and deletion. Happily, there are no confirmation dialogs or windows that pop up when you do anything with these menus — the delete command is cleverly given an extra sub-menu with one item, “confirm,” so you get that extra protection against accidents but don’t waste time with a verification click.

These commands also have keyboard equivalents. Type > to rotate an image 90 degrees clockwise, and < to rotate it 90 degrees counterclockwise. Your changes are immediately saved to the file. To delete the current image file, type Ctrl-Del.

While these commands work in slideshow mode, there are other operation modes as well, all of which are specified by command-line options. Here’s a quick rundown of them:

Multiwindow mode

The -w option starts multiwindow mode, which works like slideshow mode, but instead of displaying images in tandem in a single window, all images are loaded at once, each in a window of its own. Quitting out of a single window closes all of the windows — to just close a single window, type x inside that window.

Fullscreen mode

The -F option specifies fullscreen mode, where images are shown in the entire display. It works the same as slideshow mode and has all the same options.

Montage mode

The -m option specifies montage mode, where feh displays an image montage of thumbnails for all specified files. This mode has a lot of its own options; one of the more useful ones is -O, which doesn’t display the thumbnail montage but instead saves it to the file you specify as an argument.

Collage mode

The -c option specifies collage mode, which like montage mode creates a new image of thumbnails, but images in the montage are displayed in a random, overlapping collage.

Index mode

The -i option specifies index mode, which makes an index print — a new image of thumbnails with information about the images beneath them. The default is to just print the file’s name, but if you call index mode with the -I option instead, it also prints each file’s image (pixel) size and disk size in kilobytes. You can specify the font with the -e option.

Thumbnail mode

The -t option specifies thumbnail mode, which is one of the more useful modes — it looks just like index mode, but you can view the full-size images by clicking on their thumbnails.

List mode

The -l option specifies list mode, which outputs a listing of images with various information about them including format and size.

For instance, here’s how to get a default-style listing of all .jpg image files in the current directory:

$ feh -l *.jpg
NUM     FORMAT  WIDTH   HEIGHT  PIXELS  SIZE(bytes)     ALPHA   FILENAME
1       jpeg    800     534     427200  57600           -       0383.jpg
2       jpeg    570     800     456000  69362           -       0868.jpg
3       jpeg    800     526     420800  58995           -       0894.jpg
4       jpeg    800     599     479200  82414           -       1197.jpg
5       jpeg    800     601     480800  86439           -       1294.jpg
$

You can also customize the output (which is good for scripting) by using the -L option instead — feh’s man page describes how to specify the format.