blob: 413d422087b993e20d4eee2b1951022a5951e47e (
plain)
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
|
import time
from fractions import Fraction
from django.contrib.gis.geos import Point
import exiftool
from locations.models import Location
def readexif(image):
"""
takes an image and fills in all the exif data tracked in the image model
"""
with exiftool.ExifTool(executable_="/usr/bin/vendor_perl/exiftool") as et:
meta = et.get_metadata(image.image.path)
et.terminate()
image.exif_raw = meta
try:
image.title = meta["EXIF:ImageDescription"]
except:
try:
image.title = meta["XMP:Title"]
except:
pass
try:
image.caption = meta["EXIF:UserComment"]
except:
pass
try:
image.exif_lens = meta["MakerNotes:LensType"]
except:
try:
image.exif_lens = meta["XMP:Lens"]
except:
pass
try:
image.exif_aperture = meta["EXIF:FNumber"]
except:
pass
try:
image.exif_make = meta["EXIF:Make"]
except:
pass
try:
image.exif_model = meta["EXIF:Model"]
except:
pass
try:
image.exif_exposure = str(Fraction(float(meta["EXIF:ExposureTime"])).limit_denominator())
except:
pass
try:
image.exif_iso = meta["EXIF:ISO"]
except:
pass
try:
image.exif_focal_length = meta["EXIF:FocalLength"]
except:
pass
try:
fmt_date = time.strptime(meta["EXIF:DateTimeOriginal"], "%Y:%m:%d %H:%M:%S")
except:
pass
try:
image.exif_date = time.strftime("%Y-%m-%d %H:%M:%S", fmt_date)
except:
pass
try:
image.height = meta["File:ImageHeight"]
except:
pass
try:
image.width = meta["File:ImageWidth"]
except:
pass
return image
|