Cover by Cameron Newham, JP Vossen, Carl Albing

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

O'Reilly logo

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, "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 fpllowing 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required