Tuesday, February 10, 2009

Ordering images

My wife likes to take pictures. But she keeps putting off dumping her camera into her computer (and by extention backing them up to the family RAID). The other week I got stuck organizing a good number of months pictures from her 8GB CF. I investigated what I could do automatically. Quite a lot it turns out. The two most interesting commands here are:

  • exifautotran - auto transform (rotate) images according to the orientation sensor in the camera when the picture was taken
  • jheag -ft - time stamp the image file according to the EXIF meta-data in the image.
The rest is just a loop to organize the pictures into YYYY-MM directories. As I'm prone to, it's written in KSH, which is different enough from bash that you need to install ksh or pdksh to run it.


echo "*** Rotating images"
exifautotran *.JPG *.jpg
echo "*** Fixing time stamps"
jhead -ft *.JPG *.jpg

declare -a DATE

for f in *.JPG *.jpg; do
LC_ALL=C DATE=( $(jhead $f | awk '/^Date/ { print $3 }' | tr ':' ' ') )
mkdir -p $folder
mv $f $folder


Marcus Ramberg said...

You know programs like Adobe Lightroom does all that stuff for you, right? :)

Nicolai said...

On Linux. For free?