From c810a0af70cfefb7d9d7d5bf6c94d15ed509b584 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Thu, 3 Jun 2021 22:39:00 +0200 Subject: calculate 35mm focal length equivalent from makernote/composite data --- bin/pyggle | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'bin') diff --git a/bin/pyggle b/bin/pyggle index c3bc313..92b260d 100755 --- a/bin/pyggle +++ b/bin/pyggle @@ -8,11 +8,13 @@ import argparse from datetime import datetime import exifread +import json import os import PIL from PIL import Image from progress.bar import Bar import shutil +import subprocess import sys geocoder = None @@ -78,7 +80,12 @@ class ImageHTML: f"""{exposure_program}""" ) - def set_focus(self, f_num, exposure, focal_length, focal_length35, iso): + def set_flash(self, flash): + self.flash = f"""{flash}""" + + def set_focus( + self, f_num, exposure, focal_length, focal_length35, crop_factor, iso + ): entries = list() if f_num is not None: self.f_num = f"""f/{format_f(f_num)}""" @@ -103,6 +110,8 @@ class ImageHTML: entry = f"{format_f(focal_length)}mm" if focal_length35 is not None and focal_length35 != focal_length: entry += f" (≙ {format_f(focal_length35)}mm)" + elif crop_factor is not None: + entry += f" (≙ {format_f(focal_length * crop_factor, 0)}mm)" self.focal_length = f"""{entry}""" entries.append(self.focal_length) @@ -168,6 +177,8 @@ class ImageHTML: buf += f"Modus{self.exposure_program}\n" if self.exposure_mode: buf += f"Belichtung{self.exposure_mode}\n" + if self.flash: + buf += f"Blitz{self.flash}\n" buf += "

\n" return buf @@ -183,6 +194,18 @@ class Thumbnail: with open(filename, "rb") as f: self.exif_tag = exifread.process_file(f) + self.exiftool = dict() + try: + exiftool = subprocess.run( + ["exiftool", "-json", "-escapeHTML", "-groupNames", filename], + stdout=subprocess.PIPE, + text=True, + ) + if exiftool.returncode == 0: + self.exiftool = json.loads(exiftool.stdout)[0] + except FileNotFoundError: + pass + self.thumbname = f".thumbnails/{filename}" if not filename.lower().endswith((".jpeg", ".jpg")): self.thumbname += ".jpg" @@ -201,6 +224,7 @@ class Thumbnail: self._get_datetime() self._get_focus() self._get_makemodel() + self._get_details() if with_gps: self._get_gps() @@ -229,6 +253,12 @@ class Thumbnail: self.exif_dt = dt self.html.set_datetime(dt) + def _get_details(self): + try: + self.html.set_flash(self.exif_tag["EXIF Flash"]) + except KeyError: + pass + def _get_focus(self): entries = list() @@ -261,7 +291,11 @@ class Thumbnail: except KeyError: pass - self.html.set_focus(f_num, exposure, focal_length, focal_length35, iso) + crop_factor = self.exiftool.get("Composite:ScaleFactor35efl", None) + + self.html.set_focus( + f_num, exposure, focal_length, focal_length35, crop_factor, iso + ) try: self.html.set_exposure_mode(self.exif_tag["EXIF ExposureMode"]) -- cgit v1.2.3