图片像素替换符号

分享一个好玩的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)

# 记得修改目的的地址

 

最后出来的效果如下:

图片像素替换符号

 

上一篇:最新镜像并推送镜像至dockerhub


下一篇:【全栈之路】docker制作redis:5.0.5镜像文件到自己的dockerhub公共镜像