Skip to content
Snippets Groups Projects
Commit 2a8363e4 authored by ml bonhomme's avatar ml bonhomme :bee: Committed by Erwan Rouchet
Browse files

Do not attempt to resize images to dimensions larger than their polygon for thumbnails

parent b77279e3
No related branches found
No related tags found
1 merge request!2215Do not attempt to resize images to dimensions larger than their polygon for thumbnails
......@@ -656,9 +656,11 @@ class Element(IndexableModel):
if self.mirrored:
rotation_param = f"!{rotation_param}"
# Do no attempt to upsize small images for thumbnails
thumbnail_height = min(400, height)
return urljoin(
self.image.url + "/",
f"{x},{y},{width},{height}/,400/{rotation_param}/default.jpg"
f"{x},{y},{width},{height}/,{thumbnail_height}/{rotation_param}/default.jpg"
)
def __str__(self):
......
......@@ -38,24 +38,22 @@ class TestElement(FixtureTestCase):
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"),
(0, False, [[500, 100], [650, 100], [650, 800], [500, 800], [500, 100]], "http://server/img1/500,100,150,700/,400/0/default.jpg"),
(0, True, [[500, 100], [650, 100], [650, 800], [500, 800], [500, 100]], "http://server/img1/500,100,150,700/,400/!0/default.jpg"),
(180, False, [[500, 580], [650, 580], [650, 700], [500, 700], [500, 580]], "http://server/img1/500,580,150,120/,120/180/default.jpg"),
(180, True, [[500, 580], [650, 580], [650, 700], [500, 700], [500, 580]], "http://server/img1/500,580,150,120/,120/!180/default.jpg"),
(0, False, [[10, 20], [40, 20], [40, 60], [10, 60], [10, 20]], "http://server/img1/10,20,30,40/,40/0/default.jpg"),
(0, True, [[10, 20], [40, 20], [40, 60], [10, 60], [10, 20]], "http://server/img1/10,20,30,40/,40/!0/default.jpg"),
(180, False, [[10, 20], [40, 20], [40, 60], [10, 60], [10, 20]], "http://server/img1/10,20,30,40/,40/180/default.jpg"),
(180, True, [[10, 20], [40, 20], [40, 60], [10, 60], [10, 20]], "http://server/img1/10,20,30,40/,40/!180/default.jpg"),
]
for rotation_angle, mirrored, expected_url in cases:
for rotation_angle, mirrored, polygon, 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],
],
polygon=polygon,
rotation_angle=rotation_angle,
mirrored=mirrored,
)
......
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