diff --git a/arkindex_worker/cache.py b/arkindex_worker/cache.py index 0d4ad7844b1f1b0b1539d9295259f482a0e79321..233c7d93e7a12623219b0d2205671b912cfa77f1 100644 --- a/arkindex_worker/cache.py +++ b/arkindex_worker/cache.py @@ -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("/"): diff --git a/arkindex_worker/models.py b/arkindex_worker/models.py index 94df7bcc5b12c909eeb9f036acd258d1421908e6..d79495a672102c41a371e760066c817b0565ec56 100644 --- a/arkindex_worker/models.py +++ b/arkindex_worker/models.py @@ -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) diff --git a/tests/test_cache.py b/tests/test_cache.py index 78438aaa5aed759dfa0162f2811037ed9a37df2f..53430b303622dc1e5e67b7064e2fbe4607a3483e 100644 --- a/tests/test_cache.py +++ b/tests/test_cache.py @@ -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, diff --git a/tests/test_element.py b/tests/test_element.py index 09d45c86f9b4535aaa64612ec41aa91eeb121b04..734d5c81540841ab0ccf370b53053e573b30e792 100644 --- a/tests/test_element.py +++ b/tests/test_element.py @@ -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, )