summaryrefslogtreecommitdiff
path: root/app/media/readexif.py
diff options
context:
space:
mode:
authorluxagraf <sng@luxagraf.net>2020-12-04 11:53:47 -0500
committerluxagraf <sng@luxagraf.net>2020-12-04 11:53:47 -0500
commit67cad3ae8e7d502925e720e562d94c67df7bd7c5 (patch)
tree22a716347d6b939318d0cd41870d33dc3bd556e0 /app/media/readexif.py
parentee984ff2f1fdca4890a1864e6f71f3e94888e216 (diff)
added readexif back to save. why not.
Diffstat (limited to 'app/media/readexif.py')
-rw-r--r--app/media/readexif.py78
1 files changed, 78 insertions, 0 deletions
diff --git a/app/media/readexif.py b/app/media/readexif.py
new file mode 100644
index 0000000..70a6987
--- /dev/null
+++ b/app/media/readexif.py
@@ -0,0 +1,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() 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