From 0cef7a7903145dc019aa84722ed3fb6ca9879921 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Mon, 4 Nov 2024 08:37:17 -0800 Subject: [PATCH] Fix up the new-photo-post script Make the script a little more resilient. Print out some EXIF data that the template will use when generating the page. Update the photostream submodule commit. Remove the unused photo_exif_table.html partial. --- layouts/partials/photo_exif_table.html | 66 -------------------------- scripts/new-photo-post | 37 +++++++++++++-- themes/photostream | 2 +- 3 files changed, 33 insertions(+), 72 deletions(-) delete mode 100644 layouts/partials/photo_exif_table.html diff --git a/layouts/partials/photo_exif_table.html b/layouts/partials/photo_exif_table.html deleted file mode 100644 index a212c98..0000000 --- a/layouts/partials/photo_exif_table.html +++ /dev/null @@ -1,66 +0,0 @@ -
-
- - {{ if and .Tags.Make .Tags.Model }} - - - - {{ end }} - {{ with .Tags.LensModel }} - - - - {{ end }} - - {{- $hasLocation := and .Lat .Long -}} - {{ if $hasLocation -}} - - {{- end -}} - {{ if and .Tags.PixelXDimension .Tags.PixelYDimension -}} - - {{ end }} - - {{ if or .Tags.ISOSpeedRatings .Tags.FocalLengthIn35mmFilm .Tags.FNumber .Tags.ExposureTime }} - - - - - - - {{ end }} -
- {{- $make := .Tags.Make -}} - {{- $model := .Tags.Model -}} - {{- if in $model $make -}} - {{ .Tags.Model }} - {{- else -}} - {{ .Tags.Make }} {{ .Tags.Model }} - {{- end -}} -
{{ . }}
- {{ $lat := float .Lat }}{{ $latDir := cond (eq $lat 0) "" (cond (gt $lat 0) "N" "S") }} - {{ .Lat | lang.FormatNumber (cond (ne $lat 0) 3 0) }}º{{ $latDir }}, - {{ $long := float .Long }}{{ $longDir := cond (eq $long 0) "" (cond (gt $long 0) "E" "W") }} - {{ .Long | lang.FormatNumber (cond (ne $long 0) 3 0) }}º{{ $longDir }} - - {{- $widthpx := .Tags.PixelXDimension -}} - {{- $heightpx := .Tags.PixelYDimension -}} - {{- if and (gt $widthpx 0) (gt $heightpx 0) -}} - {{- $megapixels := div (mul $widthpx $heightpx) 1e6 -}} - {{ $megapixels | lang.FormatNumber 0 }} MP - • - {{ $widthpx }} × {{ $heightpx }} - {{- end -}} -
{{ with .Tags.ISOSpeedRatings }}ISO {{ . }}{{ end }} - {{- $focalLength := .Tags.FocalLengthIn35mmFilm | default .Tags.FocalLength -}} - {{- with $focalLength -}}{{ . }} mm{{- end -}} - {{ with .Tags.FNumber }}{{ printf "ƒ%0.1f" . }}{{ end }} - {{- with $exposureTime := .Tags.ExposureTime -}} - {{- if in $exposureTime "/" -}} - {{ . }} s - {{- else -}} - 1/{{ printf "%.0f" (div 1.0 (float $exposureTime)) }} s - {{- end -}} - {{- end -}} -
-
-
diff --git a/scripts/new-photo-post b/scripts/new-photo-post index cdc7ae9..858565e 100755 --- a/scripts/new-photo-post +++ b/scripts/new-photo-post @@ -7,12 +7,14 @@ New script. import argparse import datetime +import json import os.path import re import shutil import subprocess from PIL import Image from PIL.ExifTags import TAGS +from typing import Optional PHOTOS_CONTENT_DIR = 'content/photos' @@ -24,6 +26,7 @@ def parse_args(argv, *a, **kw): parser.add_argument('-n', '--dry-run', action='store_true') parser.add_argument('-t', '--title') parser.add_argument('-s', '--slug') + parser.add_argument('--dump-exif', action='store_true') parser.add_argument('photos', nargs='+') args = parser.parse_args(argv) return args @@ -31,9 +34,11 @@ def parse_args(argv, *a, **kw): def main(argv): args = parse_args(argv[1:], prog=argv[0]) - earliest_exif_date = None + earliest_exif_date: Optional[datetime.datetime] = None + + for index, photo in enumerate(args.photos): + print(f'image\t\t{photo}') - for photo in args.photos: try: image = Image.open(photo) except IOError: @@ -47,12 +52,34 @@ def main(argv): exif_date = datetime.datetime.strptime(date_string, '%Y:%m:%d %H:%M:%S %z') except KeyError: exif_date = datetime.datetime.strptime(friendly_exif["DateTime"], '%Y:%m:%d %H:%M:%S') + print(f'capture-time\t{exif_date.isoformat()}') - print(f'{photo} -> {exif_date.isoformat()}') + iso_rating = friendly_exif.get('ISOSpeedRatings') + if iso_rating: + print(f'iso\t\t{iso_rating}') + + focal_length_35mm = friendly_exif.get('FocalLengthIn35mmFilm') + focal_length = friendly_exif.get('FocalLength') + if focal_length or focal_length_35mm: + print(f'focal-length\t{focal_length} {focal_length_35mm}') + + fstop = friendly_exif.get('FNumber') + if fstop: + print(f'f-stop\t\t{fstop}') + + exposure_time = friendly_exif.get('ExposureTime') + if exposure_time: + print(f'exposure-time\t{exposure_time}') if not earliest_exif_date or exif_date < earliest_exif_date: earliest_exif_date = exif_date + if index < len(args.photos) - 1: + print() + + if not earliest_exif_date: + earliest_exif_date = datetime.datetime.now() + year = earliest_exif_date.year month = earliest_exif_date.month @@ -83,12 +110,12 @@ def main(argv): result = subprocess.run(hugo_command) result.check_returncode() else: - print(' '.join(hugo_command)) + print(' '.join(hugo_command), file=sys.stderr) except subprocess.CalledProcessError: print(f'Failed to create new Hugo post', file=sys.stderr) return -1 - if args.title: + if args.title and not args.dry_run: # The hugo command can't set a title for a post so I need to do it myself. index_file_path = os.path.join(post_path, 'index.md') with open(index_file_path) as index_file: diff --git a/themes/photostream b/themes/photostream index cf0aa69..63eb00b 160000 --- a/themes/photostream +++ b/themes/photostream @@ -1 +1 @@ -Subproject commit cf0aa69a8705456e31f9e89331a2ff6891f36d16 +Subproject commit 63eb00bf4a8007a0a2e6c877988874d28fa34f49