Use ImageOps.scale to fit image to width
This commit is contained in:
parent
e67aa49271
commit
25ad3f6c35
1 changed files with 5 additions and 8 deletions
13
banter.py
13
banter.py
|
@ -5,27 +5,24 @@ __doc__ = 'little script to make irc color art that will probably get you banned
|
||||||
# unbuffered mode lol
|
# unbuffered mode lol
|
||||||
|
|
||||||
import sys,time,argparse
|
import sys,time,argparse
|
||||||
from PIL import Image
|
from PIL import Image, ImageOps
|
||||||
from color import closestColor
|
from color import closestColor
|
||||||
|
|
||||||
|
|
||||||
def main(imgPath,delay,ASCIIWIDTH,COLORCHAR,FILLER):
|
def main(imgPath,delay,ASCIIWIDTH,COLORCHAR,FILLER):
|
||||||
im = Image.open(imgPath, 'r')
|
im = Image.open(imgPath, 'r')
|
||||||
|
im = ImageOps.scale(im, ASCIIWIDTH / im.width)
|
||||||
width, height = im.size
|
width, height = im.size
|
||||||
pixel_values = list(im.getdata())
|
pixel_values = list(im.getdata())
|
||||||
|
|
||||||
ipix = width // ASCIIWIDTH # // instead of / to devide with a round number
|
|
||||||
|
|
||||||
asciiHeight = height // ipix // 2
|
|
||||||
|
|
||||||
currentPixel = 0
|
currentPixel = 0
|
||||||
|
|
||||||
for y in range(asciiHeight):
|
for y in range(0, height, 2):
|
||||||
line = []
|
line = []
|
||||||
lastColor=69420
|
lastColor=69420
|
||||||
|
|
||||||
for x in range(ASCIIWIDTH):
|
for x in range(width):
|
||||||
color = closestColor(pixel_values[width*(y*(ipix*2))+(x*ipix)])
|
color = closestColor(pixel_values[width*y+x])
|
||||||
if color == lastColor:
|
if color == lastColor:
|
||||||
colorcode = ''
|
colorcode = ''
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue