did stuff?

This commit is contained in:
iou1name 2017-12-04 05:23:17 -05:00
parent e3aef08ee9
commit ee2801aa05

View File

@ -12,14 +12,14 @@ import numpy as np
import numpngw
ASCII_CHARS = "$@%#*+=-:. "
HEADERS = {'User-Agent': 'Gimme the ascii.'}
HEADERS = {'User-Agent': 'Gimme 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:
@ -221,8 +221,7 @@ if __name__=='__main__':
description="Converts an image file to ascii art.")
parser.add_argument(
"imagePath",
help="The path to the image file. May be a local path or internet \
internet URL.")
help="The path to the image file. May be a local path or internet URL.")
parser.add_argument(
"-r",
"--reverse",
@ -248,7 +247,7 @@ if __name__=='__main__':
"--color",
type=str,
help="Colorizes the ascii matrix. Currently supported modes are 'irc' \
and 'ansi'.")
and 'ansi' for generating color codes compliant with those standards.")
parser.add_argument(
"--ansi",
dest="color",