Renaming Photos with DateTime key
After many a trips, I will have photos from all the shutterbugs – covering A-Z of the trip.
Having photos from various sources, all pertaining to the same context, event or trip, how do I view the photos with out loosing the flow?
There are various software, using which I can store, manage these photos. Software album makers like Google’s Picasa and ACDSee are excellent photo managers, but how do we tackle this flow problem?
Time is the key!! All digital cameras store EXIF information along with the JPEG header. I wrote a small C code to extract the DataTime EXIF tag from my photos using the libexif library.
Using another script, I can now rename/copy images in proper order. It is assumed that there is no time difference/lag between the camera sources.
What ever you do, it will be a good idea to sync Date/Time field of all cameras before shooting or starting the trip. Alternatively, time difference +/- can be adjusted by adding 2 more lines to the script to incorporate this allowance.
This code uses libexif Exif tag parsing library.
getexifdatetime.c
#include "stdio.h"
#include "libexif/exif-utils.h"
#include "libexif/exif-data.h"
// cc -lexif getexifdatetime.c -o getexifdatetime
int
main (int argc, char **argv)
{
ExifData *ed;
ExifTag et;
ExifEntry *ee;
char val[30];
unsigned int i;
ed = exif_data_new_from_file (argv[1]);
et = EXIF_TAG_DATE_TIME;
for (i = 0; i ifd[i], et)
{
if (ee)
{
printf ("%s", exif_entry_get_value (ee, val, 30));
}
}
exif_entry_free (ee);
exif_data_free (ed);
}
rename2jpg-datekey.bash
#!/bin/bash
#####################################################################
# After getting back from an outing, collection of photos from different sources
# need to be sorted according to time stamp for better flow
# Here I use ImageMagic's identify command to get time stamp and rename/copy
# the source file to a destination with following format string
# Input: List of jpg directories,
# directory name can be user/location name for better meaning
# Output: $PREFIX-$TIME_STAMP.$SUFFIX.jpg
# All files goes to $PWD/renamed-with-date-stamp
# PREFIX can be like Image or Photo or Location name etc..
# SUFFIX can be like Author or Location etc..
#####################################################################
# Ajith/021006/First release
#####################################################################
# TODO
# GUI for input/format selection etc..
#####################################################################
DEST=$PWD/renamed-with-date-stamp
if [ $# -lt 2 ]
then
echo "No input directories given, quitting"
echo "Minimum args: PREFIX and Input DIRECTORY[..]"
exit
else
# PREFIX=Image
# PREFIX=Photo
PREFIX=$1
echo "Using $PREFIX as image prefix: $PREFIX-\$TIME-STAMP.\$SUFFIX.jpg"
shift
echo "Creating files in $DEST"
mkdir -p "$DEST"
fi
for d in $*
do
if [ ! -d "$d" ]
then
echo "$d is not a directory"
continue
fi
pushd "$d"
img_suffix=$(basename $d)
for f in *.jpg
do
if [ "$f" = "*.jpg" ]
then
echo "No more files here"
break
fi
TSF="${PREFIX} $(getexifdatetime "$f";) ${img_suffix}.jpg"
if [ "$TSF" = "${PREFIX} ${img_suffix}.jpg" ]
then
echo "$f doesn't seem to have a time stamp"
continue
fi
# Change : to _ for DOS compatibility
TSF=$(echo $TSF | tr [:] [_]
echo -n cp "$f" "$TSF .."
if [ -f "$DEST/$TSF" ]
then
echo " failed, image already exists."
else
cp "$f" "$DEST/$TSF"
echo " done"
fi
done
popd
done
This script can be easly integrated with Nautilus file manager for use from Gnome desktop.
powered by performancing firefox
2 Comments »
Leave a Reply
-
Recent
- Downloading Fedora Core 7 over slow internet connection – through proxy
- Xeta – First Service Details
- Alan, our cherrful Christmas gift
- FC5 rocks
- Laughter time
- Renaming Photos with DateTime key
- Hike from Chopta to Chandrasila peek
- Our Mussorie hike
- Various desktop blog clients for Linux
- Driving Xeta, tips & tricks
- My mobile phone; past, present & future
- Media conversion in Linux: Using mencoder/ffmpeg/transcode and other media related scripts
-
Links
-
Archives
- July 2007 (1)
- January 2007 (2)
- November 2006 (2)
- October 2006 (6)
- September 2006 (1)
- July 2006 (1)
- May 2006 (1)
- March 2006 (2)
- January 2006 (1)
-
Categories
-
RSS
Entries RSS
Comments RSS
.jpg)
It was fun writing this piece of code, but a google search for file renamer will give you more mature solutions
Recently I came across a small utility program renamer, it got pascal scripting in the backend and very powerful filter capabilities, all in a very intuitive & functional GUI. More over it worked without any hue & cry in Linux using Wine
Check out jhead: http://www.sentex.net/~mwandel/jhead/