Skip to content
Snippets Groups Projects
Commit 2d07cf35 authored by Manon Blanco's avatar Manon Blanco
Browse files

Do not compute ratio

parent 521419cf
No related branches found
No related tags found
1 merge request!395Allow a worker to specify the needed size of the image
Pipeline #131815 passed
This commit is part of merge request !395. Comments created here will be created in the context of that merge request.
......@@ -157,17 +157,8 @@ class CachedElement(Model):
max_height is None or self.image.height <= max_height
):
resize = "full"
elif max_width is not None and max_height is not None:
resize = f"{max_width},{max_height}"
else:
ratio = max(
(max_width or 0) / self.image.width,
(max_height or 0) / self.image.height,
)
new_width, new_height = int(self.image.width * ratio), int(
self.image.height * ratio
)
resize = f"{new_width},{new_height}"
resize = f"{max_width or ''},{max_height or ''}"
url = self.image.url
if not url.endswith("/"):
......
......@@ -205,15 +205,8 @@ class Element(MagicDict):
):
resize = "full"
# Resizing if the image is bigger than the wanted size.
elif max_width is not None and max_height is not None:
resize = f"{max_width},{max_height}"
else:
ratio = max(
(max_width or 0) / original_size["w"],
(max_height or 0) / original_size["h"],
)
new_width, new_height = [int(x * ratio) for x in original_size.values()]
resize = "{},{}".format(new_width, new_height)
resize = f"{max_width or ''},{max_height or ''}"
if use_full_image:
url = self.image_url(resize)
......
......@@ -240,7 +240,7 @@ def test_check_version_same_version(tmp_path):
600,
None,
400,
"http://something/full/266,400/0/default.jpg",
"http://something/full/,400/0/default.jpg",
),
(
600,
......@@ -251,7 +251,7 @@ def test_check_version_same_version(tmp_path):
400,
400,
None,
"http://something/full/400,266/0/default.jpg",
"http://something/full/400,/0/default.jpg",
),
(
400,
......
......@@ -105,7 +105,7 @@ def test_open_image_resize_portrait(mocker):
assert elt.open_image(max_height=400, use_full_image=True) == "an image!"
assert open_mock.call_count == 2
assert open_mock.call_args == mocker.call(
"http://something/full/266,400/0/default.jpg",
"http://something/full/,400/0/default.jpg",
rotation_angle=0,
mirrored=False,
)
......@@ -178,7 +178,7 @@ def test_open_image_resize_landscape(mocker):
assert elt.open_image(max_width=400, use_full_image=True) == "an image!"
assert open_mock.call_count == 2
assert open_mock.call_args == mocker.call(
"http://something/full/400,266/0/default.jpg",
"http://something/full/400,/0/default.jpg",
rotation_angle=0,
mirrored=False,
)
......@@ -388,7 +388,7 @@ def test_open_image_resize_use_full_image_false(mocker):
assert elt.open_image(max_height=200, use_full_image=False) == "an image!"
assert open_mock.call_count == 1
assert open_mock.call_args == mocker.call(
"http://zoneurl/0,0,400,600/133,200/0/default.jpg",
"http://zoneurl/0,0,400,600/,200/0/default.jpg",
rotation_angle=0,
mirrored=False,
)
......
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