Viewing Photos in an Album

Problem

You have a directory full of images like the ones you just downloaded from your digital camera. You want a quick and easy way to view them all, so that you can pick out the good ones.

Solution

Write a shell script that will generate a set of html pages so that you can view your photos with a browser. Call it mkalbum and put it somewhere like your ~/bin directory.

On the command line, cd into the directory where you want your album created (typically where your photos are located). Then run some command that will generate the list of photos that you want included in this album (e.g., ls *.jpg, but see also Finding Files Irrespective of Case), and pipe this output into the mkalbum shell script, which we will explain later. You need to put the name of the album (i.e., the name of a directory that will be created by the script) on the command line as the only argument to the shell script. It might look something like this:

$ ls *.jpg | mkalbum rugbymatch

Figure 12-1 shows a sample of the generated web page.

Sample mkalbum web page

Figure 12-1. Sample mkalbum web page

The large title is the photo (i.e., the filename); there are hyperlinks to other pages for first, last, next, and previous.

The following is the shell script (mkalbum) that will generate a set of html pages, one page per image (the line numbers are not part of the script, but are put here to make it easier to discuss): ...

Get bash Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.