Acme Sprockets

Formatting Image Files for Flickr

OK, I'll admit it... I'm a Flickr addict. One concern I've had, however, has been in posting my high-resolution images with full EXIF and IPTC tags. What I've ended up doing is processing my image files through a script that:

  • rotates (if necessary), re-sizes (to max of 1024 pixels), and mildly sharpens the image
  • adds a black border with the file name and copyright at the bottom
  • adds a watermark
  • adds a copyright to the metadata (EXIF)
  • strips all (IPTC) keywords from the metadata

This was pretty easy to do on my Linux box using Ruby (for the scripting), Image Magick (for the visual manipulation), and Exiv2 (to change the metadata).

The overall script is as follows:

#!/usr/bin/ruby
#
# Prepare an image file for upload to Flickr. Note that
# THIS PROCESS MODIFIES THE ORIGINAL FILE!
#
# 2007-07-07  Trey Kinkead    Initial version.
#

imageFile = ARGV[0]

if (!test(?f,imageFile))
  puts "ERROR: image file #{imageFile} does not exist!"
  exit 1
end

imageName = File.basename(imageFile)

watermark = 'trey'
copyright = 'Copyright Trey Kinkead'

imageOrientation = 0

# look through EXIF tags
`exiv2 -pv #{imageFile}`.each_line { |line|
  #puts line
  if (line =~ /^0x0112 /)
    args = line.split(' ')
    imageOrientation = args[5]
  end
}

# determine the "rotation" argument, if any, for Image Magick
case imageOrientation
  when '6'
    # right of camera at top
    rotateClause = '-rotate 90'
  when '8'
    # right of camera at bottom
    rotateClause = '-rotate -90'
  else
    rotateClause = ''
end


# rotate, resize, sharpen, watermark, and border
`convert #{imageFile} \
    #{rotateClause} \
    -resize '1014>x1005>' \
    -unsharp 0.5x0.5+1.0 \
    -font Helvetica-Oblique \
    -pointsize 11 -fill '#999' \
    -gravity northwest -annotate 0x0+100+100,-0 #{watermark} \
    -bordercolor black -border 5 \
    -background black \
    -gravity south -splice 0x9 \
    -font Helvetica \
    -pointsize 11 -fill '#999' \
    -gravity southwest -annotate 0x0+12,-0 #{imageName} \
    -gravity southeast -annotate 0x0+12,-0 "#{copyright}" \
    #{imageFile}`

# adjust metadata copyright, strip keywords
`exiv2 \
    -M"set Exif.Image.Copyright #{copyright}" \
    -M"del Iptc.Application2.Keywords" \
    #{imageFile}`

exit 0

Note that this script modifies the image file -- be sure to use it on a copy of the original file.

I'll post another article later about the modification I did to the Flickr Export Kipi plug-in that allows me to use this script in-line from digiKam.

Navigation