Skip to content

Commit

Permalink
Merge branch 'master' into version-2.10
Browse files Browse the repository at this point in the history
  • Loading branch information
jrief committed Sep 11, 2024
2 parents 409457b + 4bdef07 commit b6d7134
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Changes
* Drop support for Django-4.1 and earlier.
* Add support for Django-5.1.
* Experimental support for animated image formats. See documentation for more infos.
* Fix #642: Do not scale images (SVG) without size information.


2.9 (2024-07-25)
Expand Down
10 changes: 8 additions & 2 deletions easy_thumbnails/processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,15 @@ def scale_and_crop(im, size, crop=False, upscale=False, zoom=None, target=None,
target_x, target_y = [int(v) for v in size]

if crop or not target_x or not target_y:
scale = max(target_x / source_x, target_y / source_y)
scale = max(
1.0 if source_x == 0 else target_x / source_x,
1.0 if source_y == 0 else target_y / source_y,
)
else:
scale = min(target_x / source_x, target_y / source_y)
scale = min(
1.0 if source_x == 0 else target_x / source_x,
1.0 if source_y == 0 else target_y / source_y,
)

# Handle one-dimensional targets.
if not target_x:
Expand Down
10 changes: 10 additions & 0 deletions easy_thumbnails/tests/test_svg_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ def test_scale(self):
self.assertEqual(upscaled.size, (1000, 750))
self.assertEqual(upscaled.getbbox(), (0, 0, 800, 600))

empty = processors.scale_and_crop(create_image(size=(0, 0)), (1000, 1000))
self.assertEqual(empty.size, (0, 0))
self.assertEqual(empty.getbbox(), (0, 0, 0, 0))

def test_crop(self):
image = create_image()

Expand All @@ -49,3 +53,9 @@ def test_crop(self):
upscaled = processors.scale_and_crop(image, (1000, 1000), crop=True, upscale=True)
self.assertEqual(upscaled.size, (1000, 1000))
self.assertEqual(upscaled.getbbox(), (100, 0, 600, 600))

empty = processors.scale_and_crop(
create_image(size=(0, 0)), (1000, 1000), crop=True
)
self.assertEqual(empty.size, (0, 0))
self.assertEqual(empty.getbbox(), (0, 0, 0, 0))

0 comments on commit b6d7134

Please sign in to comment.