-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexif2qr.sh
executable file
·77 lines (74 loc) · 2.38 KB
/
exif2qr.sh
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
75
76
77
#!/bin/sh
parse_coord()
{
COORD_FULL="$2"
COORD=${COORD_FULL%%,*}
COORD_MIN=${COORD_FULL#*,}
COORD_MIN=${COORD_MIN%%,*}
COORD_SEC=${COORD_FULL##*,}
if test "$COORD_MIN" -eq 0 -a "$COORD_SEC" -eq 0 2>/dev/null ; then
eval "$1=\${COORD}"
return
fi
COORD_BC=$(echo "scale = 7; $COORD + $COORD_MIN / 60 + $COORD_SEC / 3600" | bc)
if ! test "${COORD_BC%%.*}" -eq "${COORD%%.*}" ; then
echo "Failed to calculate GPS coordinates with bc"
echo "Input: $2 ; split: $COORD:$COORD_MIN:$COORD_SEC ; result $COORD_BC"
exit 1
fi
eval "$1=\${COORD_BC}"
}
FILE=$1
TYPE=${2:-qr}
OUTFILE=${FILE%.*}.gps$TYPE.png
GPSNR=$(exif "$FILE" -m --ifd=GPS -t GPSLatitudeRef 2>/dev/null)
GPSN_FULL=$(exif "$FILE" -m --ifd=GPS -t GPSLatitude 2>/dev/null)
test -n "$GPSN_FULL" && parse_coord GPSN "$GPSN_FULL"
test "$GPSNR" = "S" && GPSN="-$GPSN"
GPSER=$(exif "$FILE" -m --ifd=GPS -t GPSLongitudeRef 2>/dev/null)
GPSE_FULL=$(exif "$FILE" -m --ifd=GPS -t GPSLongitude 2>/dev/null)
test -n "$GPSE_FULL" && parse_coord GPSE "$GPSE_FULL"
test "$GPSER" = "W" && GPSE="-$GPSE"
ALT=$(exif "$FILE" -m --ifd=GPS -t GPSAltitude 2>/dev/null)
ALT=${ALT%m}
ALT=${ALT%.*}
TIME=$(exif "$FILE" -m --ifd=GPS -t GPSTimeStamp 2>/dev/null)
TIME=${TIME%.*}
DATE=$(exif "$FILE" -m --ifd=GPS -t GPSDateStamp 2>/dev/null)
DATETIME=$(exif "$FILE" -m -t DateTime 2>/dev/null)
if test -z "$DATETIME" ; then
DATETIME=$(exif "$FILE" -m -t DateTimeOriginal 2>/dev/null)
fi
test -z "$DATE" && DATE="${DATETIME%% *}"
test -z "$TIME" && TIME="${DATETIME##* }"
DATE=$(echo "$DATE" | tr : -)
DATETIME=$(echo "$DATETIME" | sed -e 's/\([0-9]*\):\([0-9]*\):\([0-9]*\) /\1-\2-\3 /')
if test -n "$GPSN" ; then
STRING="geo:$GPSN,$GPSE"
# Android maps are broken and do not work with standard geo URLs
# test -n "$ALT" && STRING="$STRING,$ALT"
STRING="$STRING?d=$DATE&t=$TIME"
test -n "$ALT" && STRING="$STRING&h=$ALT"
elif test -n "$DATETIME" ; then
OUTFILE=${FILE%.*}.time$TYPE.png
STRING="$DATETIME"
else
echo "Could not find any exif information or 'exif' binary not found!"
exit 1
fi
case "$TYPE" in
qr)
qrencode -l M -m 2 -o "$OUTFILE" "$STRING"
;;
dm)
#echo "$STRING" | dmtxwrite -e b -d 3 -m 3 -o "$OUTFILE"
iec16022 -f PNG -c "$STRING" -o "$OUTFILE"
mogrify -scale 300% "$OUTFILE"
;;
txt)
echo "$STRING" > "$OUTFILE"
;;
*)
echo "Unknown target format"
esac
touch -c -d "$DATETIME" "$OUTFILE"