|
发表于 2021-8-24 11:09:50
|
显示全部楼层
from PIL import Image as i
img = i.open('/Users/wenhui/Desktop/qing.jpeg')
img = img.convert("L")
img.show()
height, width = img.size
print(height, width)
img = img.resize((int(height/4), int(width/10)))
height, width = img.size
print(height, width)
text_tools = '@#%*+=-. '
text = ''
for x in range(width):
for y in range(height):
gray = img.getpixel((int(y), int(x)))
text += text_tools[int(gray/255*8)]
text += '\n'
with open('/Users/wenhui/Desktop/qing.txt', 'w') as f:
f.write(text)
|
|