-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAsciiimage.py
More file actions
33 lines (29 loc) · 869 Bytes
/
Asciiimage.py
File metadata and controls
33 lines (29 loc) · 869 Bytes
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 numpy as np
from PIL import Image
im=Image.open(r"E:/krsna.png")
h=480
ar=(im.height/im.width)*im.width*0.7
im=im.resize((int(ar),h))
k=np.array(im)
height=im.height
width=im.width
for i in range(im.height):
for j in range(im.width):
s=np.average(k[i][j])
k[i][j][:-1]=s
#im.convert('L')
d=Image.fromarray(k)
d.save(r'E:/dsup1.png')
#lvl='''$&S@B%8&WM#*o2ahkbdpqwmAZO0QLCJUYXzcvunxrjft/\|()1{}[]?-_+~<>i!lI;:,"^`'.'''#thanks to http://paulbourke.net/dataformats/asciiart/
lvl="&.."
f=open("dip.txt","w")
s=""
with open('ascii1.txt','w')as f:
for i in range(height):
for j in range(width):
s+=lvl[int(k[i][j][0]*2/255)]#s+=lvl[int(k[i][j][0]*72/255)]
#print(s)
#print('\n')
s+='\n'
f.write(s)
s=''