Photo Processing

This details the proceedure used to process images before archival or upload to Rich Schuster.com

Update (2014-04-18):

I wrote a quick bash script to effectively perform the tasks below. With this script the steps are now as follows:

  1. Purge images
  2. Stich panoramas
  3. Change the script's UNIQUE_FOLDER
  4. Run script

Below this script is the original page which should detail the majority of the options used in the script.

#!/bin/bash  
#Copy out panorama photos (with PAN in filename), to preserve resolution  
mkdir ./pan  
mv \*PAN\* ./pan  
#Scale down remaining pictures  
ionice -c3 nice -n 17 mogrify -scale 3000x3000 -interlace plane -quality 92 -format jpg *.JPG  
rm *.JPG  
#Bring back the panoramas  
mv ./pan/*PAN.jpg ./  
rm -R ./pan  
#Rename everything according to metadata  
jhead -ft -n%Y%m%d-%H%M%S -autorot *.jpg  
#Create HTML page  
OUTFILE=output.txt  
for i in *.jpg  
do  
     moddate=$(date -r "$i" +%F)  
     moddate=$(echo ${moddate//-/.})  
     firstline='<p align="center"><a href="http://www.richschuster.com/data/uploads/pic/UNIQUE\_FOLDER/'"$i"'"><img src="http://www.richschuster.com/data/uploads/pic/UNIQUE\_FOLDER/0sm/'"$i"'" alt="'"$i"'" border=0 ></a>'  
     secondline='<p align="left">'"$moddate"' Comment on '"$i"'</p>'  
     thirdline='<hr>'  
     fourthline=' '  
     echo "$firstline" >> "$OUTFILE"  
     echo "$secondline" >> "$OUTFILE"  
     echo "$thirdline" >> "$OUTFILE"  
     echo "$fourthline" >> "$OUTFILE"  
done  
#Create thumbnails  
mkdir 0sm  
ionice -c3 nice -n 17 mogrify -path ./0sm -scale 600x600 -interlace plane -quality 80 -format jpg *.jpg

Original (2014-01-03):

I have never been satisfied with a prebuilt gallery solution, so I continue to spin my own. After a trip, the general steps I follow for processing my pictures is as follows:

  1. Purge images taken
  2. Stich any panoramas
  3. Resize & compress images
  4. Rename according to data
  5. Generate base HTML for this site
  6. Generate thumbnails
  7. Upload and add captions

Purge Images

This is easier said than done, however I need to make the conscious effort to remove duplicate, blurry, and boring images. Deleting these images first cuts down on time for these commands to execute, although processing time is only minutes. Purging images may be easier after renaming images according to date when traveling with multiple people, which allows comparing photographs of similar content side by side in the file browser.

Stitching Panoramas

Panorama stitching is relatively easy. Many modern cameras have automatic stitching built in, however using a software solution provides extra flexibility, such as which axis the panorama is centered on or the number of images used in the panorama.

The software I use is the open source Hugin. The tutorials on the website can be a bit daunting, however if your camera records focus data in the metadata of the images then Hugin is very easy and intuitive.

With the 2013 update to Hugin, it is mostly clicking through the panorama creation process; the options I once used are now integrated into the workflow. Before starting with Hugin, check the program's preferences, changing things like the output filename (I use the first image's name followed by PAN) and the default image output to JPEG.

Resize and Compressing Images

Point and shoot digital cameras have been producing beautiful images for a few years now, negating the need for a DSLR for many photographs. However, my images are still point and shoot; no tripod is used and the camera settings are set to full auto. While this takes full advantage of the optical image stabilization present in the camera, I feel hard pressed to preserve these images in their full 16MP glory.

To get a feel for an acceptable resolution, I like to keep in mind that a 1080p still is roughly 2.1MP. 4k UHDTV is 8.3MP while 8k UHDTV is 33MP. I resize to a 3000x2000 resolution (I shoot with the same aspect ratio as 35mm film, 3:2), which is 6.0MP, scaled down from the 16.1MP images my Canon ELPH320 take.

For compression levels, I spent an evening looking at the same photograph at different compression levels. For archival purposes, I came to the conclusion that 92 is acceptable with JPEG. I also looked at other formats (namely WebP), and deemed nothing mature enough to switch to (Exif, browser support, and ImageMagick support are all issues).

While multiple tools exist for compressing JPEG images, I use ImageMagick exclusively, with the command seen here:

mogrify -scale 3000x3000 -interlace plane -quality 92 -format jpg *.JPG

Mogrify edits the image in place (convert would create an output image with a different filename). The options used here are:

  • -scale 3000x3000: This keeps the maximum dimension of the image at 3000 while preserving the aspect ratio
  • -interlace plane: Interlacing allows for progressive loading of images and typically decreases file size, with larger images benefiting more
  • -quality 92: Image quality, 0-100
  • -format jpg: output format is jpg
  • *.JPG: this operation is on all files in the folder ending with .JPG (case sensitive)

Renaming Images from Metadata

The naming of files on my camera is a sequential numbering system. This works well for images from one camera, however often I also have images from my mobile phone which get sent to the bottom of the folder. Renaming according to the date of the image keeps all images in order (assuming the Exif timestamp is correct - Jhead can correct for this if misaligned).

Jhead is a command line utility for manipulating the Exif headder data of JPEG images. The command I use is here:

jhead -ft -n%Y%m%d-%H%M%S -autorot *.JPG
  • -ft: Change the system's timestamp to reflect the timestamp in the Exif data. The compression step updated the system's timestamp previously
  • -n%Y%m%d-%H%M%S: Name the file using the big-endian date
  • -autorot: Rotate the image as needed according to the Exif data. Most operating systems automatically rotate images, however web browsers do not
  • *.JPG: Perform these actions on all files ending with .JPG in the folder

Jhead has additional options that can come in handy. One in particular is the modification of the Exif timestamp. This allows correction for a camera that is not set to the correct time zone, particularly useful when combining images from multiple cameras.

Create Base HTML Structure

The following steps are the most specific to my website. This following script creates the content of my pages without the captions for images. Remeber to change the DESTINATION according to where the pictures will be stored.

#!/bin/bash

OUTFILE=output.txt  
for i in *.jpg  
do

     moddate=$(date -r "$i" +%F)  
     moddate=$(echo ${moddate//-/.})  
     firstline='<p align="center"><a href="http://www.richschuster.com/data/uploads/pic/DESTINATION/'"$i"'"><img src="http://www.richschuster.com/data/uploads/pic/DESTINATION/0sm/'"$i"'" alt="'"$i"'" border=0 ></a>'  
     secondline='<p align="left">'"$moddate"' Comment on '"$i"'</p>'  
     thirdline='<hr>'  
     fourthline=' '  
     echo "$firstline" >> "$OUTFILE"  
     echo "$secondline" >> "$OUTFILE"  
     echo "$thirdline" >> "$OUTFILE"  
     echo "$fourthline" >> "$OUTFILE"  
done

This bash script creates the file output.txt in the current directory, and adds four lines to the file for each .JPG file in the directory. I have to edit the location according to where my pictures will be stored on my web server.

Generating Thumbnail Images

Thumbnail does not seem like an applicable term, these are the images displayed on the webpage, with the original available by clicking through the thumbnail. Once again ImageMagick is used very similarly as before; although this time I have a handy script for creating the 0sm folder also.

#!/bin/bash  
mkdir 0sm  
ionice -c3 nice -n 17 mogrify -path ./0sm -scale 600x600 -interlace plane -quality 80 -format jpg *.jpg  

The images are scaled to 600 for the maximum dimension, and a quality of 80, allowing the page with hundreds of images to load in a reasonable time. The -path parameter sends the images to the described destination instead of editing them in place.

I try to also include the nice commands when running the other conversion commands in this tutorial, but have not mentioned them previously. ionice is for hard disk access, and when using a spinning disk I would say it is more important than the nice command for keeping your system responsive. The -c3 option deems the process idle class. nice prioritizes the cpu, with -n 17 giving the process a low priority.

Upload Images and Edit Page

The last step is to upload the finished product to the website, and edit captions for the images. While GetSimple CMS has an image upload GUI, I still use an SFTP client to upload my images. However, once uploaded to the correct location, the html output from earlier can be dropped into the build in editor. The advantage to using this editor is the correct image is displayed while adding captions, speeding the process.

Previous Post Next Post