18 lines
449 B
Python
18 lines
449 B
Python
from PIL import Image
|
|
import sys
|
|
p = sys.argv[1]
|
|
cols = int(sys.argv[2]) if len(sys.argv) > 2 else 120
|
|
img = Image.open(p).convert("L")
|
|
W, H = img.size
|
|
rows = max(1, int(cols * H / W / 2.1))
|
|
img2 = img.resize((cols, rows))
|
|
px = img2.load()
|
|
ramp = " .:-=+*#%@"
|
|
for y in range(rows):
|
|
line = ""
|
|
for x in range(cols):
|
|
v = px[x, y]
|
|
line += ramp[min(9, (255 - v) * 10 // 256)]
|
|
print(line)
|
|
print("size", W, H, "->", cols, rows)
|