-
Notifications
You must be signed in to change notification settings - Fork 14
/
fixjollaphotos
executable file
·74 lines (57 loc) · 1.46 KB
/
fixjollaphotos
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
DATEFORMAT="%Y-%m-%d_%H-%M-%S"
print_help(){
cat << EOI
Usage: fixjollaphotos file [files ...]
This scripts does the following for your pictures taken by your Jolla phone:
* Add the EXIF timestamp according to the filesystem timestamp
* Renames the photo like YYYY-mm-dd_HH-MM-SS
* Rotates the photo correctly
The tools exiftool and jhead must be installed.
EOI
}
check_dependencies(){
FAIL=0
for tool in $@
do
if ! hash "$tool" &> /dev/null
then
echo "The tool $tool does not exist."
FAIL=1
fi
done
if [[ "$FAIL" == 1 ]]
then
exit 1
fi
}
fix_photo(){
echo -n Fixing "$file -> "
touch --reference="$file" $file.savedate
# Add dummy timestamp, so we can it modify later
exiftool -"DateTimeOriginal=1984:05:23 13:37:42" "$file" &> /dev/null
touch --reference="$file.savedate" $file
# Set EXIF timestamp to the file timestamp
jhead -dsft "$file" &> /dev/null
rm "$file.savedate"
# Correct timezone (Timestamp of file is UTC)
TIMEOFFSET="$(date +%:z)"
jhead -ta${TIMEOFFSET} "$file" &> /dev/null
# Rotate the photo
jhead -autorot "$file" &> /dev/null
# Rename the file, print new filename and OK
jhead -nf$DATEFORMAT "$file" | awk '{ ORS=""; print $NF }'
rm "${file}_original"
echo " [OK]"
}
main(){
check_dependencies jhead exiftool
for file in "$@"
do
fix_photo "$file"
done
}
main "$@"