Commit cfc8a559 authored by Jobin Rezai's avatar Jobin Rezai

Return an error if the image can't be made smaller by percent

Before, it would just save the image to a destination folder in its original dimension
parent db638795
......@@ -300,6 +300,7 @@ def resize_image(source_image_path, resize_instructions,
new_width = int(round(source_width - (source_width * (destination_size_info / 100))))
new_height = int(round(source_height - (source_height * (destination_size_info / 100))))
# Resize image, unless the resize instruction is set to 'Do not resize'
if not resize_instructions == ResizeInstructions.DO_NOT_RESIZE:
......@@ -315,8 +316,17 @@ def resize_image(source_image_path, resize_instructions,
# Resize, with aspect ratio
im.thumbnail((new_width, new_height), Image.ANTIALIAS)
else:
# new_width and/or new_height are zero (0)
# No resize has taken place, even though we were asked to do a resize
# This will happen if the user is attempting to decrease the size of the image by percentage,
# but the source image is too small to decrease it by the asked-percentage.
# Example: an image 1x1 in dimensions cannot be made smaller by 99 percent.
return f"Error: {source_image_path} cannot resize to {new_width} width by {new_height} height"
# Save the image to a file, if we have an actual image
if im:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment