from PIL import Image
# image 图像
acsii_chars = list("MNHQ$OC?7>!:-;.")
def getchr(gray):
unit = 256/(len(acsii_chars))
return acsii_chars[int(gray // unit)] if gray < 128 else " "
# return chr(gray) if gray < 128 else " "
return "奥" if gray < 28 else " "
img_name= 'b.jpeg'
img = Image.open(img_name).resize((80, 48)).convert('L')
text = ''
for y in range(48) :
for x in range(80):
text += getchr(img.getpixel((x,y)))
text += "\n"
print(text)
f = open("helokitty.txt", "w")
f.write(text)
f.close()
harry -字符画
最新推荐文章于 2022-06-28 15:08:21 发布