From 25ad3f6c352c98500a3db3856a28676c90746e6a Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Fri, 18 Jun 2021 00:04:09 -0500 Subject: [PATCH] Use ImageOps.scale to fit image to width --- banter.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/banter.py b/banter.py index 33ac9a8..fb7f5b9 100755 --- a/banter.py +++ b/banter.py @@ -5,27 +5,24 @@ __doc__ = 'little script to make irc color art that will probably get you banned # unbuffered mode lol import sys,time,argparse -from PIL import Image +from PIL import Image, ImageOps from color import closestColor def main(imgPath,delay,ASCIIWIDTH,COLORCHAR,FILLER): im = Image.open(imgPath, 'r') + im = ImageOps.scale(im, ASCIIWIDTH / im.width) width, height = im.size pixel_values = list(im.getdata()) - ipix = width // ASCIIWIDTH # // instead of / to devide with a round number - - asciiHeight = height // ipix // 2 - currentPixel = 0 - for y in range(asciiHeight): + for y in range(0, height, 2): line = [] lastColor=69420 - for x in range(ASCIIWIDTH): - color = closestColor(pixel_values[width*(y*(ipix*2))+(x*ipix)]) + for x in range(width): + color = closestColor(pixel_values[width*y+x]) if color == lastColor: colorcode = '' else: