From c56f91da2c65d342d006edf02c4d4a4e80f2a171 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Thu, 12 Oct 2023 11:04:19 -0700 Subject: [PATCH] Write a warning if an image doesn't have an orientation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Default to 0º orientation. --- .../partials/images/orientation_angle.html | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/layouts/partials/images/orientation_angle.html b/layouts/partials/images/orientation_angle.html index 480cfd7..7ab2a57 100644 --- a/layouts/partials/images/orientation_angle.html +++ b/layouts/partials/images/orientation_angle.html @@ -1,13 +1,18 @@ -{{ $orientation := .Exif.Tags.Orientation }} -{{/* EXIF orientation is specified as an integer corresponding to a 90º rotation. */}} -{{ $angle := 0 }} -{{ if in (slice 1 2) $orientation }} - {{ $orientation = 0 }} -{{ else if in (slice 3 4) $orientation }} - {{ $orientation = 180 }} -{{ else if in (slice 5 6) $orientation }} - {{ $orientation = 90 }} -{{ else if in (slice 7 8) $orientation }} - {{ $orientation = 270 }} +{{ $orientation := 0 }} + +{{ with (int .Exif.Tags.Orientation) }} + {{/* EXIF orientation is specified as an integer corresponding to a 90º rotation. */}} + {{ if in (slice 1 2) . }} + {{ $orientation = 0 }} + {{ else if in (slice 3 4) . }} + {{ $orientation = 180 }} + {{ else if in (slice 5 6) . }} + {{ $orientation = 90 }} + {{ else if in (slice 7 8) . }} + {{ $orientation = 270 }} + {{ end }} +{{ else }} + {{ warnf "Image missing orientation: %s" . }} {{ end }} + {{ return $orientation }}