From 2aff88455ace8f2dc1f4e4d35dc5a9cc1272cb11 Mon Sep 17 00:00:00 2001 From: Mike Bryant Date: Tue, 13 Aug 2024 18:27:07 +0100 Subject: [PATCH] Temporary workaround for issue where image metadata is missing This seems to be due to Omeka's getID3() function failing. Now we fall back to the PHP getimagesize() function if the Omeka image metadata is not available. TODO: figure out why the image metadata doesn't get extracted here. --- helpers/TeiEditions_Helpers_View.php | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/helpers/TeiEditions_Helpers_View.php b/helpers/TeiEditions_Helpers_View.php index be711e3..471ffc3 100644 --- a/helpers/TeiEditions_Helpers_View.php +++ b/helpers/TeiEditions_Helpers_View.php @@ -155,13 +155,7 @@ function tei_editions_render_document_images($item) $images = []; foreach ($item->getFiles() as $file) { if (preg_match('/.+\.(png|jpg|tif)$/', $file->original_filename)) { - $res = ''; - if ($file->metadata != '') { - $info = json_decode($file->metadata, true); - if (isset($info["video"]) and isset($info["video"]["resolution_x"])) { - $res = $info["video"]["resolution_x"] . 'x' . $info["video"]["resolution_y"]; - } - } + $res = tei_editions_get_image_sizes($file); $images[] = [ "path" => $file->getWebPath(), "thumb" => $file->getWebPath("thumbnail"), @@ -348,4 +342,20 @@ function tei_editions_render_map($data, $width = 425, $height = 350) // TODO } return ""; +} + +function tei_editions_get_image_sizes($file) +{ + if ($file->metadata != '') { + $info = json_decode($file->metadata, true); + if (isset($info["video"]) and isset($info["video"]["resolution_x"])) { + return $info["video"]["resolution_x"] . 'x' . $info["video"]["resolution_y"]; + } + } + + // Log an error here because metadata has not been correctly + // set for this file. + error_log("No metadata for file: " . $file->original_filename); + $size = getimagesize($file->getWebPath()); + return $size[0] . 'x' . $size[1]; } \ No newline at end of file