From fa7f4494b59f486a4ea140dd6a1f5c03ecf83a72 Mon Sep 17 00:00:00 2001 From: Alexander O'Neill Date: Wed, 7 Feb 2024 16:09:19 -0400 Subject: [PATCH] 959-iiif-width-height-caching Add option to skip retrieveing TIFF and JP2 dimensions from IIIF server. --- .../config/schema/islandora_iiif.schema.yml | 3 +++ .../src/Plugin/views/style/IIIFManifest.php | 18 +++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/modules/islandora_iiif/config/schema/islandora_iiif.schema.yml b/modules/islandora_iiif/config/schema/islandora_iiif.schema.yml index e02f443f..69ed0d7a 100644 --- a/modules/islandora_iiif/config/schema/islandora_iiif.schema.yml +++ b/modules/islandora_iiif/config/schema/islandora_iiif.schema.yml @@ -25,6 +25,9 @@ views.style.iiif_manifest: structured_text_term: type: string label: "Structured text term" + getdimensions_from_sewrver: + type: boolean + label: "Retrieve image dimensions from IIIF server" search_endpoint: type: string label: "Search endpoint path" diff --git a/modules/islandora_iiif/src/Plugin/views/style/IIIFManifest.php b/modules/islandora_iiif/src/Plugin/views/style/IIIFManifest.php index 77763458..28dc8e2a 100644 --- a/modules/islandora_iiif/src/Plugin/views/style/IIIFManifest.php +++ b/modules/islandora_iiif/src/Plugin/views/style/IIIFManifest.php @@ -272,6 +272,9 @@ $this->addSearchEndpoint($json, $url_components); $annotation_id = $iiif_base_id . '/annotation/' . $entity->id(); [$width, $height] = $this->getCanvasDimensions($iiif_url, $image, $mime_type); + if ($width == 0) { + continue; + } $tmp_canvas = [ // @see https://iiif.io/api/presentation/2.1/#canvas @@ -385,9 +388,11 @@ $this->addSearchEndpoint($json, $url_components); // As a last resort, get it from the IIIF server. // This can be very slow and will fail if there are too many pages. - $dimensions = $this->iiifInfo->getImageDimensions($image->entity); - if ($dimensions !== FALSE) { - return $dimensions; + if ($this->options['get_dimensions_from_server']) { + $dimensions = $this->iiifInfo->getImageDimensions($image->entity); + if ($dimensions !== FALSE) { + return $dimensions; + } } return [0, 0]; @@ -560,6 +565,13 @@ $this->addSearchEndpoint($json, $url_components); '#description' => $this->t('Term indicating the media that holds structured text, such as hOCR, for the given object. Use this if the text is on a separate media from the tile source.'), ]; + $form['get_dimensions_from_server'] = [ + '#type' => 'checkbox', + '#title' => $this->t("Retrieve image dimensions from IIIF server"), + '#description' => $this->t("For TIFFs and JP2s, if the media doesn't have width and height values populated, as a last resort, retrieve the info from the IIIF server. This can be very slow and is not recommended."), + '#default_value' => $this->options['get_dimensions_from_server'], + ]; + $form['search_endpoint'] = [ '#type' => 'textfield', '#title' => $this->t("Search endpoint path."),