changed scale_image() size argument to maxDim
This commit is contained in:
parent
e3aef08ee9
commit
74446a332e
12
ascii.py
12
ascii.py
|
@ -15,11 +15,11 @@ ASCII_CHARS = "$@%#*+=-:. "
|
||||||
HEADERS = {'User-Agent': 'Gimme the ascii.'}
|
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
|
Resizes an image while preserving the aspect ratio. Chooses the
|
||||||
dimension to scale by based on whichever is larger, ensuring that
|
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,
|
Because text characters are typically pretty close to a 1:2 rectangle,
|
||||||
we weight the width twice as much.
|
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_height = image.size
|
||||||
original_width = original_width * 2
|
original_width = original_width * 2
|
||||||
if original_width > original_height:
|
if original_width > original_height:
|
||||||
if original_width > size[0]:
|
if original_width > maxDim:
|
||||||
new_width = size[0]
|
new_width = maxDim
|
||||||
aspect_ratio = original_height/float(original_width)
|
aspect_ratio = original_height/float(original_width)
|
||||||
new_height = int(aspect_ratio * new_width)
|
new_height = int(aspect_ratio * new_width)
|
||||||
else:
|
else:
|
||||||
new_width, new_height = image.size
|
new_width, new_height = image.size
|
||||||
else:
|
else:
|
||||||
if original_height > size[1]:
|
if original_height > maxDim:
|
||||||
new_height = size[1]
|
new_height = maxDim
|
||||||
aspect_ratio = original_width/float(original_height)
|
aspect_ratio = original_width/float(original_height)
|
||||||
new_width = int(aspect_ratio * new_height)
|
new_width = int(aspect_ratio * new_height)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user