did stuff?
This commit is contained in:
parent
e3aef08ee9
commit
ee2801aa05
19
ascii.py
19
ascii.py
|
@ -12,14 +12,14 @@ import numpy as np
|
||||||
import numpngw
|
import numpngw
|
||||||
|
|
||||||
ASCII_CHARS = "$@%#*+=-:. "
|
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
|
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:
|
||||||
|
@ -221,8 +221,7 @@ if __name__=='__main__':
|
||||||
description="Converts an image file to ascii art.")
|
description="Converts an image file to ascii art.")
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"imagePath",
|
"imagePath",
|
||||||
help="The path to the image file. May be a local path or internet \
|
help="The path to the image file. May be a local path or internet URL.")
|
||||||
internet URL.")
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-r",
|
"-r",
|
||||||
"--reverse",
|
"--reverse",
|
||||||
|
@ -248,7 +247,7 @@ if __name__=='__main__':
|
||||||
"--color",
|
"--color",
|
||||||
type=str,
|
type=str,
|
||||||
help="Colorizes the ascii matrix. Currently supported modes are 'irc' \
|
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(
|
parser.add_argument(
|
||||||
"--ansi",
|
"--ansi",
|
||||||
dest="color",
|
dest="color",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user