-
Notifications
You must be signed in to change notification settings - Fork 2
/
exiftest.py
50 lines (44 loc) · 1.51 KB
/
exiftest.py
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
import os
import shutil
import traceback
from lycheemodel import ExifData
from PIL import Image
import sys
from PIL.ExifTags import TAGS
if __name__ == '__main__':
file = sys.argv[1]
print file
exif = ExifData()
img = Image.open(file)
if hasattr(img, '_getexif'):
exifinfo = img._getexif()
if exifinfo is not None:
for tag, value in exifinfo.items():
decode = TAGS.get(tag, tag)
if decode != "MakerNote":
print decode, value
if decode == "Orientation":
exif.orientation = value
if decode == "Make":
exif.make = value
if decode == "MaxApertureValue":
exif.aperture = value
if decode == "FocalLength":
exif.focal = value
if decode == "ISOSpeedRatings":
exif.iso = value
if decode == "Model":
exif.model = value
if decode == "ExposureTime":
exif.shutter = value
if decode == "DateTime":
exif.takedate = value.split(" ")[0]
if decode == "DateTime":
exif.taketime = value.split(" ")[1]
if exif.orientation not in (0, 1):
# There is somthing to do
if exif.orientation == 6:
# rotate 90° clockwise
print "ROTATE!!!!!"
img.rotate(90)
img.save(file + "ok")