Skip to content
Snippets Groups Projects
Commit f2f9d08a authored by Erwan Rouchet's avatar Erwan Rouchet Committed by Bastien Abadie
Browse files

Add rotation and mirroring to IIIF thumbnail URLs

parent 51d2cf28
No related branches found
No related tags found
1 merge request!1550Add rotation and mirroring to IIIF thumbnail URLs
......@@ -370,11 +370,22 @@ class Element(IndexableModel):
@property
def iiif_thumbnail_url(self):
"""
Same as `iiif_url`, but resized to up to 400 pixels
Same as `iiif_url`, but resized to up to 400 pixels and with rotation and mirroring
"""
iiif_url = self.iiif_url
if iiif_url:
return self.iiif_url.replace('full', ',400')
if not self.polygon or not self.image_id:
return
from arkindex.project.tools import bounding_box
x, y, width, height = bounding_box(self.polygon)
rotation_param = str(self.rotation_angle)
if self.mirrored:
rotation_param = f'!{rotation_param}'
return urljoin(
self.image.url + '/',
f'{x},{y},{width},{height}/,400/{rotation_param}/default.jpg'
)
def __str__(self):
return '{}: {}'.format(self.type.display_name, self.name)
......
from arkindex.documents.models import Element
from arkindex.project.tests import FixtureTestCase
class TestElement(FixtureTestCase):
@classmethod
def setUpTestData(cls):
super().setUpTestData()
cls.element_type = cls.corpus.types.first()
cls.image = cls.imgsrv.images.get(path='img1')
def test_iiif_url(self):
# Rotation and mirroring should be ignored in iiif_url
cases = [
(0, False),
(0, True),
(180, False),
(180, True),
]
for rotation_angle, mirrored in cases:
with self.subTest(rotation_angle=rotation_angle, mirrored=mirrored):
element = Element(
name='Something',
type=self.element_type,
image=self.image,
polygon=[
[10, 20],
[40, 20],
[40, 60],
[10, 60],
[10, 20],
],
rotation_angle=rotation_angle,
mirrored=mirrored,
)
self.assertEqual(element.iiif_url, 'http://server/img1/10,20,30,40/full/0/default.jpg')
def test_iiif_thumbnail_url(self):
cases = [
(0, False, 'http://server/img1/10,20,30,40/,400/0/default.jpg'),
(0, True, 'http://server/img1/10,20,30,40/,400/!0/default.jpg'),
(180, False, 'http://server/img1/10,20,30,40/,400/180/default.jpg'),
(180, True, 'http://server/img1/10,20,30,40/,400/!180/default.jpg'),
]
for rotation_angle, mirrored, expected_url in cases:
with self.subTest(rotation_angle=rotation_angle, mirrored=mirrored):
element = Element(
name='Something',
type=self.element_type,
image=self.image,
polygon=[
[10, 20],
[40, 20],
[40, 60],
[10, 60],
[10, 20],
],
rotation_angle=rotation_angle,
mirrored=mirrored,
)
self.assertEqual(element.iiif_thumbnail_url, expected_url)
def test_no_image_no_url(self):
element = Element(
name='Something',
type=self.element_type,
)
self.assertIsNone(element.iiif_url)
self.assertIsNone(element.iiif_thumbnail_url)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment