猫史档案馆


【Python作品分享】小姐姐字符画风格处理【作品秀】

用户:tom_ztom_z查看:0 回复:1 评论:0 创建时间:2020-12-23T16:18:21


【作品展示】

center_image

 

【作品介绍】

字符风格转化

 

【作品源代码】

from PIL import Image, ImageDraw
import matplotlib.pyplot as plt

#图片宽高
width, height = (240, 240)
#灰度图
img = Image.open("LiuLiu.jpg").convert("L").resize((width, height))
#plt.imshow(img)
#plt.show()

ASCII_HIGH = '''$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\|()1{}[]?-_+~<>i!lI;:,\"^`'. '''

txt = ''
for y in range(height):
    for x in range(width):
        pos = (x, y)
        gray = img.getpixel(pos)    #0~255的亮度值
        index = int(gray/256*70)
        txt += ASCII_HIGH[index]+'@'
    txt += '\n'
#print(txt)
#with open("bcm.txt",'w') as f:
#    f.write(txt)
#字符串转图片
img_new = Image.new("RGB", (width*12, height*15), "white")  # 生成空白图片
draw = ImageDraw.Draw(img_new)  # 图片转画布
draw.text((0, 0), txt, fill="black")  # 文字写入

img_new.resize((width*12, height*12)).save("LiuLiu_SoCute.jpg")

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 1下一页
面具狐狸云绾兮面具狐狸云绾兮

我只想看原图awa

点赞0


评论