-
Notifications
You must be signed in to change notification settings - Fork 3
/
imgdaten
executable file
·47 lines (41 loc) · 1.23 KB
/
imgdaten
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env bash
################################################################################
# imgdaten - image date numbering script. This script reads a directory of image
# files' EXIF data and then renumbers the files in chronological order (0000,
# 0001, 0002, etc). Helpful if a set of images were produced by two different
# cameras with different numbering schemes.
#
# Dependencies: exiftool
#
# Version 1
# Matthew Malensek <[email protected]>
################################################################################
print_usage() {
cat <<EOM
Usage: $(basename ${0}) <image_dir>
EOM
}
if ! ( which exiftool &> /dev/null ); then
echo "Couldn't find exiftool!"
echo "(http://www.sno.phy.queensu.ca/~phil/exiftool/index.html)"
exit 1
fi
dir=${1}
if [[ ! -d "${dir}" ]]; then
print_usage
exit 1
fi
echo "Reading image EXIF data..."
timelist=$(exiftool \
-p '$dateTimeOriginal'$'\t''$directory/$filename' \
-d '%s' \
"${dir}" | sort -n)
counter=0
IFS=$'\n'
for img in $(echo "${timelist}"); do
imgname=$(cut -f 2- <<< "${img}")
imgdir=$(dirname "${imgname}")
newname=$(printf "%s/%04d.%s" "${imgdir}" ${counter} "${imgname##*.}")
mv -v "${imgname}" "${newname}"
(( counter++ ))
done