From 74446a332e0332cc1a7bf3f315b3faae62c7fedf Mon Sep 17 00:00:00 2001 From: iou1name Date: Mon, 4 Dec 2017 05:19:55 -0500 Subject: [PATCH] changed scale_image() size argument to maxDim --- ascii.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ascii.py b/ascii.py index 8686757..19540a3 100755 --- a/ascii.py +++ b/ascii.py @@ -15,11 +15,11 @@ ASCII_CHARS = "$@%#*+=-:. " HEADERS = {'User-Agent': 'Gimme the ascii.'} -def scale_image(image, size=(100,100)): +def scale_image(image, maxDim=100): """ Resizes an image while preserving the aspect ratio. Chooses the dimension to scale by based on whichever is larger, ensuring that - neither width or height is ever larger than the accepted size tuple. + neither width or height is ever larger than the maxDim argument. Because text characters are typically pretty close to a 1:2 rectangle, we weight the width twice as much. @@ -27,15 +27,15 @@ def scale_image(image, size=(100,100)): original_width, original_height = image.size original_width = original_width * 2 if original_width > original_height: - if original_width > size[0]: - new_width = size[0] + if original_width > maxDim: + new_width = maxDim aspect_ratio = original_height/float(original_width) new_height = int(aspect_ratio * new_width) else: new_width, new_height = image.size else: - if original_height > size[1]: - new_height = size[1] + if original_height > maxDim: + new_height = maxDim aspect_ratio = original_width/float(original_height) new_width = int(aspect_ratio * new_height) else: