图片像素替换符号
作者:互联网
分享一个好玩的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)
# 记得修改目的的地址
最后出来的效果如下:
标签:size,符号,int,texts,height,width,像素,替换,out 来源: https://www.cnblogs.com/p40h33/p/15576592.html