将你的女神变成字符画-【绘图篇】《极客Python之效率革命》(小甲鱼)
热门回复:
- 牵淑sama:还是熟悉的声音还是熟悉的味道 还是熟悉的互谅
- 御坂12103号:长按点赞有惊喜
- 72933447870_bili:from PIL import Image
img = Image.open("1.jpg")
out = img.convert("L")
out.show()
width, height = out.size
out = out.resize((int(width *0.3),int(height*0.12)))
asciis="@#%*+=-. "
texts = ""
height=int(height*0.12)
width=int(width*0.3)
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("C:/Users/11819/Desktop/asciis.txt","w") as file:
file.write(texts)
- 雪之下の言叶:绝对路径写法:
img = Image.open("C:\\Users\\xx\\Desktop\\1.jpg")
open括号里面可以填写图片的路径信息,注意将\改成\\,我的实例中的1.jpg就是你想要打开的图片的名称+.jpg
- 乔布斯jr:感觉不是很行啊,小甲鱼,为啥我处理后的图片不成原型啊感觉少了点什么