Skip to content

Commit

Permalink
Fix SmileyChris#622 address ZeroDivisionError in scale_and_crop.
Browse files Browse the repository at this point in the history
Set X or Y scale to 1.0 when corresponding source size is 0.
  • Loading branch information
gonzalodelgado committed Aug 28, 2023
1 parent 77265b7 commit 0952a87
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions easy_thumbnails/processors.py
Expand Up @@ -174,9 +174,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

0 comments on commit 0952a87

Please sign in to comment.