-
Notifications
You must be signed in to change notification settings - Fork 3
/
img2date
executable file
·36 lines (32 loc) · 977 Bytes
/
img2date
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
#!/usr/bin/env bash
################################################################################
# img2date - renames photos based on the date/time they were captured. Uses EXIF
# information to determine the capture date.
#
# Dependencies: exiftool
#
# Version 1
# Matthew Malensek <matt@malensek.net>
################################################################################
print_usage() {
cat <<EOM
$(basename ${0}) renames photos based on the date they were captured.
Usage: $(basename ${0}) file1 file2 ... fileN
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
if [[ ${#} -lt 1 ]]; then
print_usage
exit 1
fi
for file in ${@}; do
base=$(basename "${file}")
noext="${base%.*}"
time=$(exiftool -p '$dateTimeOriginal' -d '%s' "${file}")
newname="${file[@]/${noext}/${time}}"
mv -v -i "${file}" "${newname}"
done