-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexif_read
543 lines (495 loc) · 37.4 KB
/
exif_read
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
"""
Created on Tue Apr 7 09:41:41 2020
@author: Sarah King
description: File will pull and analyze all .tifs from a directory, quantifying
how many of them fit certain conditions.
.csv file will be created with final results of analysis.
In the command prompt, you must enter a file directory (as a string),
and whether or not you want to run a bitonal test(Y/N), a color
test (Y/N), and a grayscale test (Y/N). Errors for each image are printed
according to the image type the 'Image BitsPerSample' corresponds to,
except in the case where it doesn't correspond to a test being run. In
such a case, a grayscale and color BitsPerSample defaults to the other test,
and a bitonal BitsPerSample defaults to the grayscale test
example cmd input: exifreader.py "C:\\Users\Sarah\Documents\failure test set" y Y n
"""
import os
import exifread
import argparse
import csv
# cmd user inputs
#user is able to initially input a file director and the types of
#analyses they would like to run on the file
parser = argparse.ArgumentParser()
parser.add_argument("directory", type=str,
help="Enter a directory. Please use quotation marks around it!")
parser.add_argument("bitonal", type=str.lower,
help="Would you like to test for bitonal images? Enter Y/N")
parser.add_argument("color", type=str.lower,
help="Would you like to test for color images? Enter Y/N")
parser.add_argument("grayscale", type=str.lower,
help="Would you like to test for grayscale images? Enter Y/N.")
args = parser.parse_args()
directory = args.directory
#bitonal desired fields
bitonal_fields = {'Image BitsPerSample': '1',
'Image Compression': 'T6/Group 4 Fax',
'Image XResolution': '600',
'Image YResolution': '600'}
#color image desired fields
color_fields = {'Image BitsPerSample': '[8, 8, 8]',
'Image Compression': 'Uncompressed',
'Image XResolution': '400',
'Image YResolution': '400'}
#grayscale desired fields
grayscale_fields = {'Image BitsPerSample': '8',
'Image Compression': 'Uncompressed',
'Image XResolution': '400',
'Image YResolution': '400'}
bitonal_count = 0 #total number of bitonal images
color_count = 0 #total number of color images
grayscale_count = 0 #total number of grayscale images
error_count = 0 #number of files that fail the selected test
#this creates and saves a csv to the same location as the inputted directory
w = csv.writer(open(directory + ".csv", "w"))
#this creates a key at the top of the .csv with the expected data for each test
w.writerow(["bitonal exif data"] + ['Image BitsPerSample: ' + str(bitonal_fields['Image BitsPerSample'])] +
['Image Compression: ' + str(bitonal_fields['Image Compression'])] + ['Image XResolution: ' + str(bitonal_fields['Image XResolution'])] +
['Image YResolution: ' + str(bitonal_fields['Image YResolution'])])
w.writerow(["color exif data"] + ['Image BitsPerSample: ' + str(color_fields['Image BitsPerSample'])] +
['Image Compression: ' + str(color_fields['Image Compression'])] + ['Image XResolution: ' + str(color_fields['Image XResolution'])] +
['Image YResolution: ' + str(color_fields['Image YResolution'])])
w.writerow(["grayscale exif data"] + ['Image BitsPerSample: ' + str(grayscale_fields['Image BitsPerSample'])] +
['Image Compression: ' + str(grayscale_fields['Image Compression'])] + ['Image XResolution: ' + str(grayscale_fields['Image XResolution'])] +
['Image YResolution: ' + str(grayscale_fields['Image YResolution'])])
#for each file in the directory, this will run the selected test and tell you
#which images are of which type. non .tifs are skipped entirely.
for (root, dirs, files) in os.walk(directory):
for f in files:
bitonal_error = False #these failed the bitonal test somehow
color_error = False #these failed the color test somehow
grayscale_error = False #these failed the grayscale test somehow
#counts the number of key/value pairs that match for each .tif
bitonal_check = 0
color_check = 0
grayscale_check = 0
full_file_path = os.path.join(root, f)
fname, fextension = os.path.splitext(full_file_path)
print("Inspecting file: {0}".format(full_file_path))
if fextension == ".tif":
image = open(full_file_path, 'rb')
tags = exifread.process_file(image) #returns exif tags
image.close()
#this runs all 3 tests. CHECKED AND WORKS
if args.bitonal == "y" and args.color == "y" and args.grayscale == "y":
bitonal_error = False #these failed the bitonal test somehow
color_error = False #these failed the color test somehow
grayscale_error = False #these failed the grayscale test somehow
for key, value in bitonal_fields.items():
if key not in tags: #tag is missing from exifdata!
print("Did not find field {0}, halting processing of file: {1}".format(key, f))
print("Halted processing of file {0} with exif headers: {1}".format(f, tags))
bitonal_error = True
break
if value == str(tags[key]): #key and data have matched
print("Found match of key: {0} and value: {1} in file {2}".format(key, value, f))
else: #key is present but value does not match
print("Field {0} with value {1} does not match, halting processing of file {2}".format(key,str(tags[key]), f))
print("Halted processing of file {0} with exif headers: {1}".format(f, tags))
bitonal_error = True
break
bitonal_check +=1
print("File matched: {0}".format(f))
for key, value in color_fields.items():
if key not in tags:
print("Did not find field {0}, halting processing of file: {1}".format(key, f))
print("Halted processing of file {0} with exif headers: {1}".format(f, tags))
color_error = True
break
if value == str(tags[key]):
print("Found match of key: {0} and value: {1} in file {2}".format(key, value, f))
else:
print("Field {0} with value {1} does not match, halting processing of file {2}".format(key,str(tags[key]), f))
print("Halted processing of file {0} with exif headers: {1}".format(f, tags))
color_error = True
break
color_check += 1
print("File matched: {0}".format(f))
for key, value in grayscale_fields.items():
if key not in tags:
print("Did not find field {0}, halting processing of file: {1}".format(key, f))
print("Halted processing of file {0} with exif headers: {1}".format(f, tags))
grayscale_error = True
break
if value == str(tags[key]):
print("Found match of key: {0} and value: {1} in file {2}".format(key, value, f))
else:
print("Field {0} with value {1} does not match, halting processing of file {2}".format(key,str(tags[key]), f))
print("Halted processing of file {0} with exif headers: {1}".format(f, tags))
grayscale_error = True
break
grayscale_check += 1
print("File matched: {0}".format(f))
if bitonal_error == True and color_error == True and grayscale_error == True:
error_count += 1
print("error count: " + str(error_count))
print(str(full_file_path + " failed all tests"))
#bitonal
w.writerow([full_file_path + " has the following errors: "])
if str(tags['Image BitsPerSample']) == bitonal_fields['Image BitsPerSample'] :
if str(tags['Image BitsPerSample']) != bitonal_fields['Image BitsPerSample'] :
w.writerow(['bitonal error'] + ["value " + str(tags['Image BitsPerSample']) + " in file does not match desired Image BitsPerSample: '1'"])
if str(tags['Image Compression']) != bitonal_fields['Image Compression'] :
w.writerow(['bitonal error'] + ["value " + str(tags['Image Compression']) + " in file does not match desired Image Compression: \'T6/Group 4 Fax\'"])
if str(tags['Image XResolution']) != bitonal_fields['Image XResolution'] :
w.writerow(['bitonal error'] + ["value " + str(tags['Image XResolution']) + " in file does not match desired Image XResolution: \'600\'"])
if str(tags['Image YResolution']) != bitonal_fields['Image YResolution'] :
w.writerow(['bitonal error'] + ["value " + str(tags['Image YResolution']) + " in file does not match desired Image YResolution: \'600\'"])
#color
elif str(tags['Image BitsPerSample']) == color_fields['Image BitsPerSample']:
if str(tags['Image BitsPerSample']) != color_fields['Image BitsPerSample'] :
w.writerow(['color error'] + ["value " + str(tags['Image BitsPerSample']) + " in file does not match desired Image BitsPerSample: \'[8, 8, 8]\'"])
if str(tags['Image Compression']) != color_fields['Image Compression'] :
w.writerow(['color error'] + ["value " + str(tags['Image Compression']) + " in file does not match desired Image Compression: \'Uncompressed\'"])
if str(tags['Image XResolution']) != color_fields['Image XResolution'] :
w.writerow(['color error'] + ["value " + str(tags['Image XResolution']) + " in file does not match desired Image XResolution: \'400\'"])
if str(tags['Image YResolution']) != color_fields['Image YResolution'] :
w.writerow(['color error'] + ["value " + str(tags['Image YResolution']) + " in file does not match desired Image YResolution: \'400\'"])
#grayscale
elif str(tags['Image BitsPerSample']) == grayscale_fields['Image BitsPerSample'] :
if str(tags['Image BitsPerSample']) != grayscale_fields['Image BitsPerSample'] :
w.writerow(['grayscale error'] + ["value " + str(tags['Image BitsPerSample']) + " in file does not match desired Image BitsPerSample: \'8\'"])
if str(tags['Image Compression']) != grayscale_fields['Image Compression'] :
w.writerow(['grayscale error'] + ["value " + str(tags['Image Compression']) + " in file does not match desired Image Compression: \'Uncompressed\'"])
if str(tags['Image XResolution']) != grayscale_fields['Image XResolution'] :
w.writerow(['grayscale error'] + ["value " + str(tags['Image XResolution']) + " in file does not match desired Image XResolution: \'400\'"])
if str(tags['Image YResolution']) != grayscale_fields['Image YResolution'] :
w.writerow(['grayscale error'] + ["value " + str(tags['Image YResolution']) + " in file does not match desired Image YResolution: \'400\'"])
else :
w.writerow(["Image BitsPerSample " + str(tags['Image BitsPerSample']) + " does not match any known test"])
if bitonal_check == 4 :
bitonal_count +=1
elif bitonal_check != 4 :
bitonal_check = 0
if color_check == 4 :
color_count += 1
elif color_check != 4:
color_check = 0
if grayscale_check == 4 :
grayscale_count += 1
elif grayscale_check != 4:
grayscale_check = 0
#this runs the bitonal and color test
elif args.bitonal == "y" and args.color == "y" and args.grayscale == "n":
for key, value in bitonal_fields.items():
if key not in tags: #tag is missing from exifdata!
print("Did not find field {0}, halting processing of file: {1}".format(key, f))
print("Halted processing of file {0} with exif headers: {1}".format(f, tags))
bitonal_error = True
break
if value == str(tags[key]): #key and data have matched
print("Found match of key: {0} and value: {1} in file {2}".format(key, value, f))
else: #key is present but value does not match
print("Field {0} with value {1} does not match, halting processing of file {2}".format(key,str(tags[key]), f))
print("Halted processing of file {0} with exif headers: {1}".format(f, tags))
bitonal_error = True
break
bitonal_check +=1
print("File matched: {0}".format(f))
for key, value in color_fields.items():
if key not in tags:
print("Did not find field {0}, halting processing of file: {1}".format(key, f))
print("Halted processing of file {0} with exif headers: {1}".format(f, tags))
color_error = True
break
if value == str(tags[key]):
print("Found match of key: {0} and value: {1} in file {2}".format(key, value, f))
else:
print("Field {0} with value {1} does not match, halting processing of file {2}".format(key,str(tags[key]), f))
print("Halted processing of file {0} with exif headers: {1}".format(f, tags))
color_error = True
break
color_check += 1
print("File matched: {0}".format(f))
if bitonal_error == True and color_error == True:
error_count += 1
print(str(full_file_path + " failed all tests"))
w.writerow([full_file_path + " has the following errors:"])
#bitonal errors
if str(tags['Image BitsPerSample']) == bitonal_fields['Image BitsPerSample']:
if str(tags['Image BitsPerSample']) != bitonal_fields['Image BitsPerSample'] :
w.writerow(['bitonal error'] + ["value " + str(tags['Image BitsPerSample']) + " in file does not match desired Image BitsPerSample: '1'"])
if str(tags['Image Compression']) != bitonal_fields['Image Compression'] :
w.writerow(['bitonal error'] + ["value " + str(tags['Image Compression']) + " in file does not match desired Image Compression: \'T6/Group 4 Fax\'"])
if str(tags['Image XResolution']) != bitonal_fields['Image XResolution'] :
w.writerow(['bitonal error'] + ["value " + str(tags['Image XResolution']) + " in file does not match desired Image XResolution: \'600\'"])
if str(tags['Image YResolution']) != bitonal_fields['Image YResolution'] :
w.writerow(['bitonal error'] + ["value " + str(tags['Image YResolution']) + " in file does not match desired Image YResolution: \'600\'"])
#color and grayscale get checked as color
elif str(tags['Image BitsPerSample']) == color_fields['Image BitsPerSample'] or str(tags['Image BitsPerSample']) == grayscale_fields['Image BitsPerSample']:
if str(tags['Image BitsPerSample']) != color_fields['Image BitsPerSample'] :
w.writerow(['color error'] + ["value " + str(tags['Image BitsPerSample']) + " in file does not match desired Image BitsPerSample: \'[8, 8, 8]\'"])
if str(tags['Image Compression']) != color_fields['Image Compression'] :
w.writerow(['color error'] + ["value " + str(tags['Image Compression']) + " in file does not match desired Image Compression: \'Uncompressed\'"])
if str(tags['Image XResolution']) != color_fields['Image XResolution'] :
w.writerow(['color error'] + ["value " + str(tags['Image XResolution']) + " in file does not match desired Image XResolution: \'400\'"])
if str(tags['Image YResolution']) != color_fields['Image YResolution'] :
w.writerow(['color error'] + ["value " + str(tags['Image YResolution']) + " in file does not match desired Image YResolution: \'400\'"])
#not color, bitonal, or grayscale
else :
w.writerow(["Image BitsPerSample " + str(tags['Image BitsPerSample']) + " does not match any known test"])
if bitonal_check == 4 :
bitonal_count +=1
elif bitonal_check != 4 :
bitonal_check = 0
if color_check == 4 :
color_count += 1
elif color_check != 4:
color_check = 0
#this runs the bitonal and grayscale test
elif args.bitonal == "y" and args.color == "n" and args.grayscale == "y":
for key, value in bitonal_fields.items():
if key not in tags: #tag is missing from exifdata!
print("Did not find field {0}, halting processing of file: {1}".format(key, f))
print("Halted processing of file {0} with exif headers: {1}".format(f, tags))
bitonal_error = True
break
if value == str(tags[key]): #key and data have matched
print("Found match of key: {0} and value: {1} in file {2}".format(key, value, f))
else: #key is present but value does not match
print("Field {0} with value {1} does not match, halting processing of file {2}".format(key,str(tags[key]), f))
print("Halted processing of file {0} with exif headers: {1}".format(f, tags))
bitonal_error = True
break
bitonal_check +=1
print("File matched: {0}".format(f))
for key, value in grayscale_fields.items():
if key not in tags:
print("Did not find field {0}, halting processing of file: {1}".format(key, f))
print("Halted processing of file {0} with exif headers: {1}".format(f, tags))
grayscale_error = True
break
if value == str(tags[key]):
print("Found match of key: {0} and value: {1} in file {2}".format(key, value, f))
else:
print("Field {0} with value {1} does not match, halting processing of file {2}".format(key,str(tags[key]), f))
print("Halted processing of file {0} with exif headers: {1}".format(f, tags))
grayscale_error = True
break
grayscale_check += 1
print("File matched: {0}".format(f))
if bitonal_error == True and grayscale_error == True:
error_count += 1
print(str(full_file_path + " failed both tests"))
w.writerow([full_file_path + " has the following errors: "])
#bitonal
if str(tags['Image BitsPerSample']) == bitonal_fields['Image BitsPerSample']:
if str(tags['Image BitsPerSample']) != bitonal_fields['Image BitsPerSample'] :
w.writerow(['bitonal error'] + ["value " + str(tags['Image BitsPerSample']) + " in file does not match desired Image BitsPerSample: '1'"])
if str(tags['Image Compression']) != bitonal_fields['Image Compression'] :
w.writerow(['bitonal error'] + ["value " + str(tags['Image Compression']) + " in file does not match desired Image Compression: 'T6/Group 4 Fax'"])
if str(tags['Image XResolution']) != bitonal_fields['Image XResolution'] :
w.writerow(['bitonal error'] + ["value " + str(tags['Image XResolution']) + " in file does not match desired Image XResolution: '600'"])
if str(tags['Image YResolution']) != bitonal_fields['Image YResolution'] :
w.writerow(['bitonal error'] + ["value " + str(tags['Image YResolution']) + " in file does not match desired Image YResolution: '600'"])
#grayscale and color get tested as grayscale
elif str(tags['Image BitsPerSample']) == grayscale_fields['Image BitsPerSample'] or str(tags['Image BitsPerSample']) == color_fields['Image BitsPerSample']:
if str(tags['Image BitsPerSample']) != grayscale_fields['Image BitsPerSample'] :
w.writerow(['grayscale error'] + ["value " + str(tags['Image BitsPerSample']) + " in file does not match desired Image BitsPerSample: \'8\'"])
if str(tags['Image Compression']) != grayscale_fields['Image Compression'] :
w.writerow(['grayscale error'] + ["value " + str(tags['Image Compression']) + " in file does not match desired Image Compression: \'Uncompressed\'"])
if str(tags['Image XResolution']) != grayscale_fields['Image XResolution'] :
w.writerow(['grayscale error'] + ["value " + str(tags['Image XResolution']) + " in file does not match desired Image XResolution: \'400\'"])
if str(tags['Image YResolution']) != grayscale_fields['Image YResolution'] :
w.writerow(['grayscale error'] + ["value " + str(tags['Image YResolution']) + " in file does not match desired Image YResolution: \'400\'"])
#not color, bitonal, or grayscale
else :
w.writerow(["Image BitsPerSample " + str(tags['Image BitsPerSample']) + " does not match any known test"])
if bitonal_check == 4 :
bitonal_count +=1
elif bitonal_check != 4 :
bitonal_check = 0
if grayscale_check == 4 :
grayscale_count += 1
elif grayscale_check != 4:
grayscale_check = 0
#this runs the color and grayscale test
elif args.bitonal == 'n' and args.color == 'y' and args.grayscale == 'y':
for key, value in color_fields.items():
if key not in tags:
print("Did not find field {0}, halting processing of file: {1}".format(key, f))
print("Halted processing of file {0} with exif headers: {1}".format(f, tags))
color_error = True
break
if value == str(tags[key]):
print("Found match of key: {0} and value: {1} in file {2}".format(key, value, f))
else:
print("Field {0} with value {1} does not match, halting processing of file {2}".format(key,str(tags[key]), f))
print("Halted processing of file {0} with exif headers: {1}".format(f, tags))
color_error = True
break
color_check += 1
print("File matched: {0}".format(f))
for key, value in grayscale_fields.items():
if key not in tags:
print("Did not find field {0}, halting processing of file: {1}".format(key, f))
print("Halted processing of file {0} with exif headers: {1}".format(f, tags))
grayscale_error = True
break
if value == str(tags[key]):
print("Found match of key: {0} and value: {1} in file {2}".format(key, value, f))
else:
print("Field {0} with value {1} does not match, halting processing of file {2}".format(key,str(tags[key]), f))
print("Halted processing of file {0} with exif headers: {1}".format(f, tags))
grayscale_error = True
break
grayscale_check += 1
print("File matched: {0}".format(f))
if color_error == True and grayscale_error == True:
error_count += 1
print(str(full_file_path + " failed both tests"))
w.writerow(["failed all tests"] + [full_file_path])
#color
if str(tags['Image BitsPerSample']) == color_fields['Image BitsPerSample'] :
if str(tags['Image BitsPerSample']) != color_fields['Image BitsPerSample'] :
w.writerow(['color error'] + ["value " + str(tags['Image BitsPerSample']) + " in file does not match desired Image BitsPerSample: \'[8, 8, 8]\'"])
if str(tags['Image Compression']) != color_fields['Image Compression'] :
w.writerow(['color error'] + ["value " + str(tags['Image Compression']) + " in file does not match desired Image Compression: \'Uncompressed\'"])
if str(tags['Image XResolution']) != color_fields['Image XResolution'] :
w.writerow(['color error'] + ["value " + str(tags['Image XResolution']) + " in file does not match desired Image XResolution: \'400\'"])
if str(tags['Image YResolution']) != color_fields['Image YResolution'] :
w.writerow(['color error'] + ["value " + str(tags['Image YResolution']) + " in file does not match desired Image YResolution: \'400\'"])
#grayscale and bitonal get checked as grayscale
elif str(tags['Image BitsPerSample']) == grayscale_fields['Image BitsPerSample'] or str(tags['Image BitsPerSample']) == bitonal_fields['Image BitsPerSample'] :
if str(tags['Image BitsPerSample']) != grayscale_fields['Image BitsPerSample'] :
w.writerow(['grayscale error'] + ["value " + str(tags['Image BitsPerSample']) + " in file does not match desired Image BitsPerSample: \'8\'"])
if str(tags['Image Compression']) != grayscale_fields['Image Compression'] :
w.writerow(['grayscale error'] + ["value " + str(tags['Image Compression']) + " in file does not match desired Image Compression: \'Uncompressed\'"])
if str(tags['Image XResolution']) != grayscale_fields['Image XResolution'] :
w.writerow(['grayscale error'] + ["value " + str(tags['Image XResolution']) + " in file does not match desired Image XResolution: \'400\'"])
if str(tags['Image YResolution']) != grayscale_fields['Image YResolution'] :
w.writerow(['grayscale error'] + ["value " + str(tags['Image YResolution']) + " in file does not match desired Image YResolution: \'400\'"])
#not color, bitonal, or grayscale
else :
w.writerow(["Image BitsPerSample " + str(tags['Image BitsPerSample']) + " does not match any known test"])
if color_check == 4 :
color_count += 1
elif color_check != 4:
color_check = 0
if grayscale_check == 4 :
grayscale_count += 1
elif grayscale_check != 4:
grayscale_check = 0
#this runs just the bitonal test
elif args.bitonal == 'y' and args.grayscale == 'n' and args.color == "n":
for key, value in bitonal_fields.items():
bitonal_error = False
if key not in tags: #tag is missing from exifdata!
print("Did not find field {0}, halting processing of file: {1}".format(key, f))
print("Halted processing of file {0} with exif headers: {1}".format(f, tags))
bitonal_error = True
break
if value == str(tags[key]): #key and data have matched
print("Found match of key: {0} and value: {1} in file {2}".format(key, value, f))
else: #key is present but value does not match
print("Field {0} with value {1} does not match, halting processing of file {2}".format(key,str(tags[key]), f))
print("Halted processing of file {0} with exif headers: {1}".format(f, tags))
bitonal_error = True
break
bitonal_check +=1
print("File matched: {0}".format(f))
if bitonal_error == True :
error_count += 1
print(str(full_file_path + " failed the bitonal test"))
#bitonal
w.writerow([full_file_path + " has the following errors: "])
if str(tags['Image BitsPerSample']) != bitonal_fields['Image BitsPerSample'] :
w.writerow(['bitonal error'] + ["value " + str(tags['Image BitsPerSample']) + " in file does not match desired Image BitsPerSample: '1'"])
if str(tags['Image Compression']) != bitonal_fields['Image Compression'] :
w.writerow(['bitonal error'] + ["value " + str(tags['Image Compression']) + " in file does not match desired Image Compression: \'T6/Group 4 Fax\'"])
if str(tags['Image XResolution']) != bitonal_fields['Image XResolution'] :
w.writerow(['bitonal error'] + ["value " + str(tags['Image XResolution']) + " in file does not match desired Image XResolution: \'600\'"])
if str(tags['Image YResolution']) != bitonal_fields['Image YResolution'] :
w.writerow(['bitonal error'] + ["value " + str(tags['Image YResolution']) + " in file does not match desired Image YResolution: \'600\'"])
if bitonal_check == 4 :
bitonal_count +=1
elif bitonal_check != 4 :
bitonal_check = 0
#this runs just the color test
elif args.color == 'y' and args.bitonal == 'n' and args.grayscale == 'n':
for key, value in color_fields.items():
colo_error = False
if key not in tags:
print("Did not find field {0}, halting processing of file: {1}".format(key, f))
print("Halted processing of file {0} with exif headers: {1}".format(f, tags))
color_error = True
break
if value == str(tags[key]):
print("Found match of key: {0} and value: {1} in file {2}".format(key, value, f))
else:
print("Field {0} with value {1} does not match, halting processing of file {2}".format(key,str(tags[key]), f))
print("Halted processing of file {0} with exif headers: {1}".format(f, tags))
color_error = True
break
color_check += 1
print("File matched: {0}".format(f))
if color_error == True :
error_count += 1
print(str(full_file_path + " failed the color test"))
w.writerow([full_file_path + " has the following errors: "])
if str(tags['Image BitsPerSample']) != color_fields['Image BitsPerSample'] :
w.writerow(['color error'] + ["value " + str(tags['Image BitsPerSample']) + " in file does not match desired Image BitsPerSample: \'[8, 8, 8]\'"])
if str(tags['Image Compression']) != color_fields['Image Compression'] :
w.writerow(['color error'] + ["value " + str(tags['Image Compression']) + " in file does not match desired Image Compression: \'Uncompressed\'"])
if str(tags['Image XResolution']) != color_fields['Image XResolution'] :
w.writerow(['color error'] + ["value " + str(tags['Image XResolution']) + " in file does not match desired Image XResolution: \'400\'"])
if str(tags['Image YResolution']) != color_fields['Image YResolution'] :
w.writerow(['color error'] + ["value " + str(tags['Image YResolution']) + " in file does not match desired Image YResolution: \'400\'"])
if color_check == 4 :
color_count += 1
elif color_check != 4:
color_check = 0
#this runs just the grayscale test.
elif args.grayscale == 'y' and args.bitonal == 'n' and args.color == 'n':
grayscale_error = False
for key, value in grayscale_fields.items():
if key not in tags:
print("Did not find field {0}, halting processing of file: {1}".format(key, f))
print("Halted processing of file {0} with exif headers: {1}".format(f, tags))
grayscale_error = True
break
if value == str(tags[key]):
print("Found match of key: {0} and value: {1} in file {2}".format(key, value, f))
else:
print("Field {0} with value {1} does not match, halting processing of file {2}".format(key,str(tags[key]), f))
print("Halted processing of file {0} with exif headers: {1}".format(f, tags))
grayscale_error = True
break
grayscale_check += 1
print("File matched: {0}".format(f))
if grayscale_error == True :
error_count += 1
print(str(full_file_path + " failed the grayscale test"))
w.writerow([full_file_path + " has the following errors:"])
if str(tags['Image BitsPerSample']) != grayscale_fields['Image BitsPerSample'] :
w.writerow(['grayscale error'] + ["value " + str(tags['Image BitsPerSample']) + " in file does not match desired Image BitsPerSample: \'8\'"])
if str(tags['Image Compression']) != grayscale_fields['Image Compression'] :
w.writerow(['grayscale error'] + ["value " + str(tags['Image Compression']) + " in file does not match desired Image Compression: \'Uncompressed\'"])
if str(tags['Image XResolution']) != grayscale_fields['Image XResolution'] :
w.writerow(['grayscale error'] + ["value " + str(tags['Image XResolution']) + " in file does not match desired Image XResolution: \'400\'"])
if str(tags['Image YResolution']) != grayscale_fields['Image YResolution'] :
w.writerow(['grayscale error'] + ["value " + str(tags['Image YResolution']) + " in file does not match desired Image YResolution: \'400\'"])
if grayscale_check == 4 :
grayscale_count += 1
elif grayscale_check != 4:
grayscale_check = 0
else:
print("File is not in .tif format")
print("error_count = " + str(error_count))
print("bitonal_count = " + str(bitonal_count))
print("color_count = " + str(color_count))
print("grayscale_count = " + str(grayscale_count))
w.writerow(["error_count = "] + [str(error_count)])
w.writerow(["bitonal_count = "] + [str(bitonal_count)])
w.writerow(["color_count = "] + [str(color_count)])
w.writerow(["grayscale_count = "] + [str(grayscale_count)])