分享一个好玩的python脚本
from PIL import Image img = Image.open(r"C:\Users\P\Desktop\123.jpg","r") out = img.convert("L") print(out.size) width,height = out.size out = out.resize((int(width*0.3),int(height*0.3*0.5))) width,height = out.size print(width,height) asciis = "@%#*+=-. " texts = "" for row in range(height): for col in range(width): gray = out.getpixel((col,row)) texts += asciis[int(gray / 255 * 8)] texts += "\n" with open(r"C:\Users\P\Desktop\3.txt","w") as f: f.write(texts)
# 记得修改目的的地址
最后出来的效果如下: