From e374f7ed59ac592e448f3ee1b8bd4d2c20594436 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Thu, 11 Jan 2024 19:13:21 +0100 Subject: [PATCH] ViewPhoto: prepare meta data in controller; change layout --- controllers/ViewPhoto.php | 43 ++++++++++++++++++++++++---- public/css/default.css | 30 ++++++++------------ templates/PhotoPage.php | 59 +++++++++------------------------------ 3 files changed, 62 insertions(+), 70 deletions(-) diff --git a/controllers/ViewPhoto.php b/controllers/ViewPhoto.php index c7f58158..82cb41a7 100644 --- a/controllers/ViewPhoto.php +++ b/controllers/ViewPhoto.php @@ -37,10 +37,9 @@ class ViewPhoto extends HTMLController { $page = new PhotoPage($this->photo); - // Exif data? - $exif = EXIF::fromFile($this->photo->getFullPath()); - if ($exif) - $page->setExif($exif); + // Any (EXIF) meta data? + $metaData = $this->prepareMetaData(); + $page->setMetaData($metaData); // What tag are we browsing? $tag = isset($_GET['in']) ? Tag::fromId($_GET['in']) : null; @@ -73,9 +72,43 @@ class ViewPhoto extends HTMLController // ... deleting, that is. else { - $photo->unlinkTags([(int) $_POST['id_tag']]); + $this->photo->unlinkTags([(int) $_POST['id_tag']]); echo json_encode(['success' => true]); exit; } } + + private function prepareMetaData() + { + if (!($exif = EXIF::fromFile($this->photo->getFullPath()))) + throw new UnexpectedValueException('Photo file not found!'); + + $metaData = []; + + if (!empty($exif->created_timestamp)) + $metaData['Date Taken'] = date("j M Y, H:i:s", $exif->created_timestamp); + + if ($author = $this->photo->getAuthor()) + $metaData['Uploaded by'] = $author->getfullName(); + + if (!empty($exif->camera)) + $metaData['Camera Model'] = $exif->camera; + + if (!empty($exif->shutter_speed)) + $metaData['Shutter Speed'] = $exif->shutterSpeedFraction(); + + if (!empty($exif->aperture)) + $metaData['Aperture'] = number_format($exif->aperture, 1); + + if (!empty($exif->focal_length)) + $metaData['Focal Length'] = $exif->focal_length; + + if (!empty($exif->iso)) + $metaData['ISO Speed'] = $exif->iso; + + if (!empty($exif->software)) + $metaData['Software'] = $exif->software; + + return $metaData; + } } diff --git a/public/css/default.css b/public/css/default.css index c119c9dc..84e02f18 100644 --- a/public/css/default.css +++ b/public/css/default.css @@ -523,7 +523,7 @@ a#previous_photo:hover, a#next_photo:hover { right: 0; } -#sub_photo h2, #sub_photo h3, #photo_exif_box h3, #user_actions_box h3 { +#sub_photo h2, #sub_photo h3 { margin-bottom: 1rem; } #sub_photo #tag_list { @@ -542,18 +542,17 @@ a#previous_photo:hover, a#next_photo:hover { opacity: 1.0; } - -#photo_exif_box dt { +.photo_meta { + background-color: var(--bs-body-bg); + box-shadow: 0 0.25rem 0.5rem rgba(0,0,0,0.1); +} +.photo_meta li { + padding: 0.6rem 1rem; +} +.photo_meta h4 { + font-family: 'Coda', sans-serif; + font-size: inherit; font-weight: bold; - float: left; - clear: left; - width: 120px; -} -#photo_exif_box dt:after { - content: ':'; -} -#photo_exif_box dd { - float: left; margin: 0; } @@ -583,13 +582,6 @@ a#previous_photo:hover, a#next_photo:hover { #previous_photo, #next_photo { display: none; } - - #sub_photo, #photo_exif_box { - float: none; - margin: 30px 0; - padding: 10px; - width: auto; - } } diff --git a/templates/PhotoPage.php b/templates/PhotoPage.php index 1b61f2df..2decf31c 100644 --- a/templates/PhotoPage.php +++ b/templates/PhotoPage.php @@ -8,8 +8,8 @@ class PhotoPage extends Template { - protected $photo; - private $exif; + private $photo; + private $metaData; private $tag; public function __construct(Image $photo) @@ -100,52 +100,19 @@ class PhotoPage extends Template private function photoMeta() { echo ' -
-

EXIF

-
'; +
    '; - if (!empty($this->exif->created_timestamp)) + foreach ($this->metaData as $header => $body) + { echo ' -
    Date Taken
    -
    ', date("j M Y, H:i:s", $this->exif->created_timestamp), '
    '; +
  • +

    ', $header, '

    + ', $body, ' +
  • '; + } echo ' -
    Uploaded by
    -
    ', $this->photo->getAuthor()->getfullName(), '
    '; - - if (!empty($this->exif->camera)) - echo ' -
    Camera Model
    -
    ', $this->exif->camera, '
    '; - - if (!empty($this->exif->shutter_speed)) - echo ' -
    Shutter Speed
    -
    ', $this->exif->shutterSpeedFraction(), '
    '; - - if (!empty($this->exif->aperture)) - echo ' -
    Aperture
    -
    f/', number_format($this->exif->aperture, 1), '
    '; - - if (!empty($this->exif->focal_length)) - echo ' -
    Focal Length
    -
    ', $this->exif->focal_length, ' mm
    '; - - if (!empty($this->exif->iso)) - echo ' -
    ISO Speed
    -
    ', $this->exif->iso, '
    '; - - if (!empty($this->exif->software)) - echo ' -
    Software
    -
    ', $this->exif->software, '
    '; - - echo ' -
-
'; + '; } private function taggedPeople() @@ -240,9 +207,9 @@ class PhotoPage extends Template '; } - public function setExif(EXIF $exif) + public function setMetaData(array $metaData) { - $this->exif = $exif; + $this->metaData = $metaData; } public function userActions()