-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpicture.py
65 lines (48 loc) · 1.59 KB
/
picture.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import cv2
import os
import sys
def getSettings():
shading_1 = " .:-=+*#%@"
shading_2 = " .'`^\",:;Il!i><~+_-?][}{1)(|\\/tfjrxnuvczXYUJCLQ0OZmwqpdbkhao*#MW&8%B@$"
shading_3 = " ░▒▓█"
shading = shading_1
resolution = (237, 67)
path = 'image.png'
argv = sys.argv[1:]
if not all("=" in arg for arg in argv):
return [argv]
arg_dict = {arg.split("=")[0]: arg.split("=")[1] for arg in argv}
if "s" in arg_dict:
if arg_dict["s"] == "1":
shading = shading_1
elif arg_dict["s"] == "2":
shading = shading_2
else:
shading = shading_3
if "w" in arg_dict:
resolution = (int(arg_dict["w"]), resolution[1])
if "h" in arg_dict:
resolution = (resolution[0], int(arg_dict["h"]))
if "p" in arg_dict:
path = arg_dict["p"]
return shading, resolution, path
def loadImage(resolution, path):
return cv2.cvtColor(cv2.resize(cv2.imread(path), resolution), cv2.COLOR_BGR2GRAY)
def transform(image, shading):
return "\n".join(["".join([shading[(round((pixel * (len(shading) - 1)) / 256))] for pixel in list(row)]) for row in list(image)])
def display(asc):
os.system('cls')
print(asc, end="")
input()
def main():
response = getSettings()
if len(response) == 1:
print(response)
return None
else:
shading, resolution, path = response
image = loadImage(resolution, path)
asc = transform(image, shading)
display(asc)
if __name__ == '__main__':
main()