/
check-thumbnail.sh
executable file
·231 lines (216 loc) · 8.55 KB
/
check-thumbnail.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#!/bin/sh
# Test thumbnail operations
. ./check-vars.sh
readonly tmpfile="check-thumbnail-out.tmp"
readonly tmpimg="check-thumbnail-image.jpg"
readonly tmpimg2="check-thumbnail-image2.jpg"
readonly srcimg="$SRCDIR/testdata/no-exif.jpg"
# Run this in the C locale so the messages are known
LANG=C; export LANG
LANGUAGE=C; export LANGUAGE
echo Create EXIF with thumbnail
cp "$srcimg" "$tmpimg"
# Add image to itself as its own thumbnail
$EXIFEXE --create-exif --insert-thumbnail="$tmpimg" --output="$tmpimg" "$tmpimg" > "$tmpfile" 2>&1
test $? -eq 0 || { echo Incorrect return code; exit 1; }
$DIFFEXE - "$tmpfile" <<EOF
Wrote file 'check-thumbnail-image.jpg'.
EOF
test $? -eq 0 || exit 1
echo Check that thumbnail and tags were added
# Strip off date & time
$EXIFEXE --no-fixup "$tmpimg" 2>&1 | sed -e "/Date and Time/s/|.*$/|/" > "$tmpfile"
$DIFFEXE - "$tmpfile" <<EOF
EXIF tags in 'check-thumbnail-image.jpg' ('Motorola' byte order):
--------------------+----------------------------------------------------------
Tag |Value
--------------------+----------------------------------------------------------
X-Resolution |72
Y-Resolution |72
Resolution Unit |Inch
Date and Time |
YCbCr Positioning |Centered
Compression |Internal error (unknown value 0)
X-Resolution |72
Y-Resolution |72
Resolution Unit |Inch
Exif Version |Exif Version 2.1
Components Configura|Y Cb Cr -
FlashPixVersion |FlashPix Version 1.0
Color Space |Uncalibrated
Pixel X Dimension |0
Pixel Y Dimension |0
--------------------+----------------------------------------------------------
EXIF data contains a thumbnail (857 bytes).
EOF
test $? -eq 0 || exit 1
echo Add thumbnail to file that already has a thumbnail
$EXIFEXE --insert-thumbnail="$srcimg" --output="$tmpimg2" "$tmpimg" 2>&1 | sed -e "/Date and Time/s/|.*$/|/" > "$tmpfile"
test $? -eq 0 || { echo Incorrect return code; exit 1; }
$DIFFEXE - "$tmpfile" <<EOF
EXIF tags in 'check-thumbnail-image.jpg' ('Motorola' byte order):
--------------------+----------------------------------------------------------
Tag |Value
--------------------+----------------------------------------------------------
X-Resolution |72
Y-Resolution |72
Resolution Unit |Inch
Date and Time |
YCbCr Positioning |Centered
Compression |Internal error (unknown value 0)
X-Resolution |72
Y-Resolution |72
Resolution Unit |Inch
Exif Version |Exif Version 2.1
Components Configura|Y Cb Cr -
FlashPixVersion |FlashPix Version 1.0
Color Space |Uncalibrated
Pixel X Dimension |0
Pixel Y Dimension |0
--------------------+----------------------------------------------------------
EXIF data contains a thumbnail (857 bytes).
Wrote file 'check-thumbnail-image2.jpg'.
EOF
test $? -eq 0 || exit 1
echo Extract thumbnail
$EXIFEXE --extract-thumbnail --output="$tmpimg2" "$tmpimg" > "$tmpfile" 2>&1
test $? -eq 0 || { echo Incorrect return code; exit 1; }
$DIFFEXE - "$tmpfile" <<EOF
Wrote file 'check-thumbnail-image2.jpg'.
EOF
test $? -eq 0 || exit 1
cmp "$srcimg" "$tmpimg2"
test $? -eq 0 || { echo Thumbnail was corrupted; exit 1; }
echo Remove thumbnail
$EXIFEXE --remove-thumbnail --output="$tmpimg2" "$tmpimg" 2>&1 | sed -e "/Date and Time/s/|.*$/|/" > "$tmpfile"
test $? -eq 0 || { echo Incorrect return code; exit 1; }
$DIFFEXE - "$tmpfile" <<EOF
EXIF tags in 'check-thumbnail-image.jpg' ('Motorola' byte order):
--------------------+----------------------------------------------------------
Tag |Value
--------------------+----------------------------------------------------------
X-Resolution |72
Y-Resolution |72
Resolution Unit |Inch
Date and Time |
YCbCr Positioning |Centered
Exif Version |Exif Version 2.1
Components Configura|Y Cb Cr -
FlashPixVersion |FlashPix Version 1.0
Color Space |Uncalibrated
Pixel X Dimension |0
Pixel Y Dimension |0
--------------------+----------------------------------------------------------
Wrote file 'check-thumbnail-image2.jpg'.
EOF
test $? -eq 0 || exit 1
echo Check that thumbnail and tags were removed
$EXIFEXE --no-fixup "$tmpimg2" 2>&1 | sed -e "/Date and Time/s/|.*$/|/" > "$tmpfile"
$DIFFEXE - "$tmpfile" <<EOF
EXIF tags in 'check-thumbnail-image2.jpg' ('Motorola' byte order):
--------------------+----------------------------------------------------------
Tag |Value
--------------------+----------------------------------------------------------
X-Resolution |72
Y-Resolution |72
Resolution Unit |Inch
Date and Time |
YCbCr Positioning |Centered
Exif Version |Exif Version 2.1
Components Configura|Y Cb Cr -
FlashPixVersion |FlashPix Version 1.0
Color Space |Uncalibrated
Pixel X Dimension |0
Pixel Y Dimension |0
--------------------+----------------------------------------------------------
EOF
test $? -eq 0 || exit 1
echo Extract thumbnail from file without thumbnail
$EXIFEXE --extract-thumbnail --output="$tmpimg" "$tmpimg2" > "$tmpfile" 2>&1
test $? -eq 1 || { echo Incorrect return code; exit 1; }
$DIFFEXE - "$tmpfile" <<EOF
'check-thumbnail-image2.jpg' does not contain a thumbnail!
EOF
test $? -eq 0 || exit 1
echo Remove thumbnail on file without thumbnail
$EXIFEXE --remove-thumbnail --output="$tmpimg" "$tmpimg2" 2>&1 | sed -e "/Date and Time/s/|.*$/|/" > "$tmpfile"
test $? -eq 0 || { echo Incorrect return code; exit 1; }
$DIFFEXE - "$tmpfile" <<EOF
EXIF tags in 'check-thumbnail-image2.jpg' ('Motorola' byte order):
--------------------+----------------------------------------------------------
Tag |Value
--------------------+----------------------------------------------------------
X-Resolution |72
Y-Resolution |72
Resolution Unit |Inch
Date and Time |
YCbCr Positioning |Centered
Exif Version |Exif Version 2.1
Components Configura|Y Cb Cr -
FlashPixVersion |FlashPix Version 1.0
Color Space |Uncalibrated
Pixel X Dimension |0
Pixel Y Dimension |0
--------------------+----------------------------------------------------------
Wrote file 'check-thumbnail-image.jpg'.
EOF
test $? -eq 0 || exit 1
echo Check adding nonexistent thumbnail
$EXIFEXE --insert-thumbnail="does-not-exist" --output="$tmpimg2" "$tmpimg" > "$tmpfile" 2>&1
test $? -eq 1 || { echo Incorrect return code; exit 1; }
$DIFFEXE - "$tmpfile" <<EOF
Could not open 'does-not-exist' (No such file or directory)!
EOF
test $? -eq 0 || exit 1
echo Create tag on thumbnail IFD with no thumbnail
cp "$srcimg" "$tmpimg"
# First, create a file with an extra tag on IFD 1 and verify that it's there.
$EXIFEXE --create-exif --ifd=1 --tag=XResolution --set-value="99 1" --output="$tmpimg" "$tmpimg" > "$tmpfile" 2>&1
test $? -eq 0 || { echo Incorrect return code; exit 1; }
$EXIFEXE --no-fixup "$tmpimg" 2>&1 | sed -e "/Date and Time/s/|.*$/|/" > "$tmpfile"
$DIFFEXE - "$tmpfile" <<EOF
EXIF tags in 'check-thumbnail-image.jpg' ('Motorola' byte order):
--------------------+----------------------------------------------------------
Tag |Value
--------------------+----------------------------------------------------------
X-Resolution |72
Y-Resolution |72
Resolution Unit |Inch
Date and Time |
YCbCr Positioning |Centered
X-Resolution |99
Exif Version |Exif Version 2.1
Components Configura|Y Cb Cr -
FlashPixVersion |FlashPix Version 1.0
Color Space |Uncalibrated
Pixel X Dimension |0
Pixel Y Dimension |0
--------------------+----------------------------------------------------------
EOF
test $? -eq 0 || exit 1
echo Check that thumbnail tags are removed with no thumbnail
# The tag on IFD 1 is removed because the file has no thumbnail.
$EXIFEXE --output="$tmpimg" "$tmpimg" | sed -e "/Date and Time/s/|.*$/|/" 2>&1 > "$tmpfile"
test $? -eq 0 || { echo Incorrect return code; exit 1; }
$DIFFEXE - "$tmpfile" <<EOF
EXIF tags in 'check-thumbnail-image.jpg' ('Motorola' byte order):
--------------------+----------------------------------------------------------
Tag |Value
--------------------+----------------------------------------------------------
X-Resolution |72
Y-Resolution |72
Resolution Unit |Inch
Date and Time |
YCbCr Positioning |Centered
Exif Version |Exif Version 2.1
Components Configura|Y Cb Cr -
FlashPixVersion |FlashPix Version 1.0
Color Space |Uncalibrated
Pixel X Dimension |0
Pixel Y Dimension |0
--------------------+----------------------------------------------------------
EOF
test $? -eq 0 || exit 1
# Cleanup
echo PASSED
rm -f "$tmpfile" "$tmpimg" "$tmpimg2"