Skip to content

Commit

Permalink
Revert "Add correct image sizes"
Browse files Browse the repository at this point in the history
This reverts commit 5854733.
  • Loading branch information
ipf committed Sep 22, 2021
1 parent e6aaefb commit c80ec30
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 66 deletions.
2 changes: 1 addition & 1 deletion Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ services:
arguments: ["@cache_filesystem", "@source_filesystem"]

Subugoe\IIIFBundle\Service\PresentationService:
arguments: ["@router", "%image%", "%presentation%", '@Subugoe\IIIFBundle\Service\FileService']
arguments: ["@router", "%image%", "%presentation%"]

#
# The following definition is an example on how to create the translator
Expand Down
72 changes: 7 additions & 65 deletions Service/PresentationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,20 @@ class PresentationService implements PresentationServiceInterface
public const CONTEXT_IMAGE = 'images';
public const CONTEXT_MANIFESTS = 'manifests';

private const DEFAULT_HEIGHT = 400;
private const DEFAULT_WIDTH = 300;

private RouterInterface $router;

private array $imageConfiguration;

private array $presentationConfiguration;

private FileServiceInterface $fileService;

/**
* PresentationService constructor.
*/
public function __construct(RouterInterface $router, array $imageConfiguration, array $presentationConfiguration, FileServiceInterface $fileService)
public function __construct(RouterInterface $router, array $imageConfiguration, array $presentationConfiguration)
{
$this->router = $router;
$this->imageConfiguration = $imageConfiguration;
$this->presentationConfiguration = $presentationConfiguration;
$this->fileService = $fileService;
}

/**
Expand Down Expand Up @@ -172,12 +166,11 @@ public function getRange(\Subugoe\IIIFModel\Model\Document $document, string $na
public function getCanvas(\Subugoe\IIIFModel\Model\Document $document, string $canvasId, int $physicalStructureId = -1): Canvas
{
$this->router->setContext($this->setRoutingContext(self::CONTEXT_MANIFESTS));
$physicalStructure = $document->getPhysicalStructure($physicalStructureId);

$images = $this->getImages($document, $canvasId);

if (-1 !== $physicalStructureId) {
$label = $physicalStructure->getLabel();
$label = $document->getPhysicalStructure($physicalStructureId)->getLabel();
} else {
$label = $this->getLabelForCanvas($document, $canvasId);
}
Expand All @@ -190,9 +183,11 @@ public function getCanvas(\Subugoe\IIIFModel\Model\Document $document, string $c
],
UrlGeneratorInterface::ABSOLUTE_URL))
->setLabel($label)
->setHeight(400)
->setWidth(300)
->setImages($images);

if (!empty($physicalStructure->getAnnotation())) {
if (!empty($document->getPhysicalStructure($physicalStructureId)->getAnnotation())) {
$annotationList = new AnnotationList();
$annotationList
->setId($this->router->generate('subugoe_iiif_annotation-list', ['id' => $document->getId(), 'name' => $canvasId], UrlGeneratorInterface::ABSOLUTE_URL))
Expand All @@ -201,22 +196,6 @@ public function getCanvas(\Subugoe\IIIFModel\Model\Document $document, string $c
$canvas->setOtherContent([$annotationList]);
}

if ($physicalStructure->getFilename()) {
$dimensions = $this->getImageDimenstions($physicalStructure->getFilename());
/*
* @see https://www.php.net/manual/de/function.getimagesize.php#refsect1-function.getimagesize-returnvalues
* 0 = width
* 1 = height
*/
$canvas
->setWidth($dimensions[0])
->setHeight($dimensions[1]);
} else {
$canvas
->setHeight(self::DEFAULT_HEIGHT)
->setWidth(self::DEFAULT_WIDTH);
}

return $canvas;
}

Expand All @@ -233,7 +212,6 @@ public function getImage(\Subugoe\IIIFModel\Model\Document $document, string $im
'quality' => 'default',
'format' => $document->getImageFormat(),
];
$imageFileName = $this->getFilenameFromImageId($document, $imageId);

$image = new GenericResource();
$resource = new ResourceData();
Expand All @@ -252,20 +230,10 @@ public function getImage(\Subugoe\IIIFModel\Model\Document $document, string $im
$resource
->setId($this->router->generate('subugoe_iiif_image_base', ['identifier' => $imageParameters['identifier']], UrlGeneratorInterface::ABSOLUTE_URL))
->setFormat($format)
->setWidth(300)
->setHeight(400)
->setService($imageService);

if ('' !== $imageFileName) {
$dimensions = $this->getImageDimenstions($imageFileName);

$resource
->setWidth($dimensions[0])
->setHeight($dimensions[1]);
} else {
$resource
->setWidth(self::DEFAULT_WIDTH)
->setHeight(self::DEFAULT_HEIGHT);
}

$image
->setId($this->router->generate('subugoe_iiif_imagepresentation', ['id' => $document->getId(), 'name' => $imageId], UrlGeneratorInterface::ABSOLUTE_URL))
->setResource($resource)
Expand Down Expand Up @@ -300,32 +268,6 @@ public function getSequence(\Subugoe\IIIFModel\Model\Document $document, string
return $sequence;
}

private function getImageDimenstions(string $filename): array
{
$image = $this->fileService->getSourceFilesystem()->read($filename);
$dimensions = getimagesizefromstring($image);
/*
* @see https://www.php.net/manual/de/function.getimagesize.php#refsect1-function.getimagesize-returnvalues
* 0 = width
* 1 = height
*/

return [$dimensions[0], $dimensions[1]];
}

private function getFilenameFromImageId(
\Subugoe\IIIFModel\Model\Document $document, string $imageId): string
{
/** @var PhysicalStructure $physicalStructure */
foreach ($document->getPhysicalStructures() as $physicalStructure) {
if ($imageId === $physicalStructure->getIdentifier()) {
return $physicalStructure->getFilename();
}
}

return '';
}

/**
* @throws IIIFException
*/
Expand Down

0 comments on commit c80ec30

Please sign in to comment.