Browse Source

Issue #959: Improve IIIF manifest generation performance.

Store image dimensions in with and height fields.
959-iiif-performance
Alexander O'Neill 1 year ago
parent
commit
42eec19ec0
  1. 19
      modules/islandora_iiif/src/Plugin/views/style/IIIFManifest.php

19
modules/islandora_iiif/src/Plugin/views/style/IIIFManifest.php

@ -214,7 +214,7 @@ class IIIFManifest extends StylePluginBase {
$canvas_id = $iiif_base_id . '/canvas/' . $entity->id(); $canvas_id = $iiif_base_id . '/canvas/' . $entity->id();
$annotation_id = $iiif_base_id . '/annotation/' . $entity->id(); $annotation_id = $iiif_base_id . '/annotation/' . $entity->id();
[$width, $height] = $this->getCanvasDimensions($iiif_url, $image, $mime_type); [$width, $height] = $this->getCanvasDimensions($iiif_url, $image, $mime_type, $entity);
$tmp_canvas = [ $tmp_canvas = [
// @see https://iiif.io/api/presentation/2.1/#canvas // @see https://iiif.io/api/presentation/2.1/#canvas
@ -272,11 +272,19 @@ class IIIFManifest extends StylePluginBase {
* The image field. * The image field.
* @param string $mime_type * @param string $mime_type
* The mime type of the image. * The mime type of the image.
* @param \Drupal\Core\Entity\EntityInterface $entity
* The image entity.
* *
* @return [string] * @return [string]
* The width and height of the image. * The width and height of the image.
*/ */
protected function getCanvasDimensions(string $iiif_url, FieldItemInterface $image, string $mime_type) { protected function getCanvasDimensions(string $iiif_url, FieldItemInterface $image, string $mime_type, $entity) {
if ($entity->hasField('field_height') && !$entity->get('field_height')->isEmpty() && $entity->hasField('field_width') && !$entity->get('field_width')->isEmpty()) {
$width = $entity->get('field_width')->value;
$height = $entity->get('field_height')->value;
}
else {
// Try to fetch the IIIF metadata for the image.
try { try {
$info_json = $this->httpClient->get($iiif_url)->getBody(); $info_json = $this->httpClient->get($iiif_url)->getBody();
$resource = json_decode($info_json, TRUE); $resource = json_decode($info_json, TRUE);
@ -305,6 +313,13 @@ class IIIFManifest extends StylePluginBase {
} }
} }
} }
}
if ($entity->hasField('field_height') && $entity->get('field_height')->isEmpty() && $entity->hasField('field_width') && $entity->get('field_width')->isEmpty()) {
$entity->set('field_width', $width);
$entity->set('field_height', $height);
$entity->save();
}
return [$width, $height]; return [$width, $height];
} }

Loading…
Cancel
Save