0
点赞
收藏
分享

微信扫一扫

python图片转txt

夕阳孤草 2022-09-20 阅读 114
前端开发


python图片转txt_其它


图片前后比较,因为图片是晚上拍的,效果可能欠佳

from PIL import Image
img = Image.open("D:\PyCharm实例\zihuaxiang\IMG_20190513_215846-.png")
out = img.convert("L")
out.size
width, height = out.size
out = out.resize((int(width * 0.5),int(height * 0.5)))
width, height = out.size
print(width,height)
print(out.getpixel((100,100)))
print(out.getpixel((200,200)))
asciis = "@%#+=-. "
texts = " "
for row in range(height):
for col in range(width):
gray = out.getpixel((col,row))
texts += asciis[int(gray / 255 * 2)]
texts += "\n"
with open("D:/PyCharm实例/zihuaxiang/new2.txt","w") as file:
file.write(texts)

欢迎您关注我的公众.号:学习微站(studysth)

python图片转txt_其它_02


举报

相关推荐

0 条评论