Compare commits

...

1 Commits

Author SHA1 Message Date
Alexander O'Neill 42eec19ec0 Issue #959: Improve IIIF manifest generation performance. 1 year ago
  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();
$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 = [
// @see https://iiif.io/api/presentation/2.1/#canvas
@ -272,11 +272,19 @@ class IIIFManifest extends StylePluginBase {
* The image field.
* @param string $mime_type
* The mime type of the image.
* @param \Drupal\Core\Entity\EntityInterface $entity
* The image entity.
*
* @return [string]
* 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 {
$info_json = $this->httpClient->get($iiif_url)->getBody();
$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];
}

Loading…
Cancel
Save