2020-12-19 02:09:39 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import sys,time
|
|
|
|
from PIL import Image
|
|
|
|
from color import closestColor
|
|
|
|
|
|
|
|
ASCIIWIDTH=80
|
|
|
|
COLORCHAR='\x03{},{}' # this will be String.format()'ted with two args
|
|
|
|
FILLER='.'
|
|
|
|
|
|
|
|
if len(sys.argv) < 2:
|
|
|
|
raise Exception('you must supply an image')
|
|
|
|
|
|
|
|
im = Image.open(sys.argv[1], 'r')
|
|
|
|
width, height = im.size
|
|
|
|
pixel_values = list(im.getdata())
|
|
|
|
|
|
|
|
ipix = width // ASCIIWIDTH # // instead of / to devide with a round number
|
|
|
|
|
2020-12-19 02:56:15 +00:00
|
|
|
asciiHeight = height // ipix // 2
|
2020-12-19 02:09:39 +00:00
|
|
|
|
|
|
|
for y in range(asciiHeight):
|
|
|
|
line = []
|
|
|
|
lastColor=69420
|
|
|
|
|
|
|
|
for x in range(ASCIIWIDTH):
|
2020-12-19 02:56:15 +00:00
|
|
|
color = closestColor(pixel_values[width*(y*(ipix*2))+(x*ipix)])
|
2020-12-19 02:09:39 +00:00
|
|
|
if color == lastColor:
|
|
|
|
colorcode = ''
|
|
|
|
else:
|
|
|
|
colorcode =COLORCHAR.format(color, color)
|
|
|
|
line.append(colorcode+FILLER)
|
|
|
|
lastColor=color
|
|
|
|
|
|
|
|
print(''.join(line))
|
|
|
|
if len(sys.argv) > 2:
|
|
|
|
time.sleep(float(sys.argv[2]))
|