Skip to content

Commit

Permalink
Merge pull request #8 from discoverygarden/feature/explicit-iiif-thum…
Browse files Browse the repository at this point in the history
…bnail

DGIR-142 : Feature/explicit iiif thumbnail
  • Loading branch information
nchiasson-dgi authored Jan 17, 2024
2 parents 539ca19 + b105571 commit 743d2e5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/Event/V3/ImageBodyEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ImageBodyEvent extends Event {
*/
public function __construct(
protected FileInterface $image,
protected string $size = 'full',
) {
}

Expand Down Expand Up @@ -58,4 +59,14 @@ public function getBodies() : array {
return $this->bodies;
}

/**
* Get the requested size hint.
*
* @return string
* The size hint requested for the event.
*/
public function getSize() : string {
return $this->size;
}

}
15 changes: 13 additions & 2 deletions src/EventSubscriber/V3/BaseImageBodyEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ public function baseBody(ImageBodyEvent $event) : void {
* The file for which to generate a bod.
* @param array $extra
* An associative array of extra values to be set in the body.
* @param string $size
* The requested size.
*
* @return array
* The body.
*
* @throws \Drupal\Component\Plugin\Exception\PluginException
*/
protected function getBody(?string $slug, FileInterface $file, array $extra = []) : array {
protected function getBody(?string $slug, FileInterface $file, array $extra = [], string $size = 'full') : array {
if (!$slug) {
return [];
}
Expand All @@ -73,7 +75,7 @@ protected function getBody(?string $slug, FileInterface $file, array $extra = []
'{identifier}' => rawurlencode($id_plugin->getIdentifier($file)),
]);
return [
'id' => "$base_id/full/full/0/default.jpg",
'id' => "{$base_id}/full/{$size}/0/default.jpg",
'type' => 'Image',
'format' => 'image/jpeg',
'service' => [
Expand All @@ -96,6 +98,9 @@ public function imageV1Body(ImageBodyEvent $event) : void {
'type' => 'ImageService1',
'profile' => 'level2',
],
// @todo Validate that the size spec is valid for IIIF-I V1, maybe map to
// something similar if unsupported?
$event->getSize(),
));
}

Expand All @@ -110,6 +115,9 @@ public function imageV2Body(ImageBodyEvent $event) : void {
'type' => 'ImageService2',
'profile' => 'level2',
],
// @todo Validate that the size spec is valid for IIIF-I V2, maybe map to
// something similar if unsupported?
$event->getSize(),
));
}

Expand All @@ -124,6 +132,9 @@ public function imageV3Body(ImageBodyEvent $event) : void {
'type' => 'ImageService3',
'profile' => 'level2',
],
// @todo Validate that the size spec is valid for IIIF-I V3, maybe map to
// something similar if unsupported?
$event->getSize(),
));
}

Expand Down

0 comments on commit 743d2e5

Please sign in to comment.