-
Notifications
You must be signed in to change notification settings - Fork 1
/
public-version.py
33 lines (24 loc) · 1.15 KB
/
public-version.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import sys
from PIL import Image
from colorama import Style
try:
image_path = sys.argv[1]
image = Image.open(image_path)
width, height = image.size
aspect_ratio = height/width
new_width = 120
new_height = aspect_ratio * new_width * 0.55
image = image.resize((int(new_width), int(new_height)))
img = image.convert('L')
pixels = img.getdata()
ASCII_CHARS = ['`', '^', ',', ':', ';', 'I', 'l', '!', 'i', '~', '+', '_', '-', '?', ']', '[', '}',
'{', '1', ')', '(', '|', 't', 'f', 'j', 'r', 'x', 'n', 'u', 'v', 'c', 'z', 'X', 'Y', 'U', 'J', 'C', 'L', 'Q', '0', 'O', 'Z', 'm', 'w', 'q', 'p', 'd', 'b', 'k', 'h', 'a', 'o', '*', '#', 'M', 'W', '&', '8', '%', 'B', '@', '$']
new_pixels = [ASCII_CHARS[pixel//25] for pixel in pixels]
new_pixels = ''.join(new_pixels)
new_pixels_count = len(new_pixels)
ascii_image = [new_pixels[index:index + new_width]
for index in range(0, new_pixels_count, new_width)]
ascii_image = "\n".join(ascii_image)
print(Style.DIM+ascii_image)
except FileNotFoundError:
print(f"{image_path} image path not found, please check and try again")