ASCII艺术是指使用ASCII码来表达图片。
python中已有现成的ASCII艺术库,但是不能使用pip安装,需要在github上下载安装。
源代码地址:https://github.com/jontonsoup4/ascii_art
安装后发现原作者的参数配置有问题,生成的图片比例有问题。然后自己进行了修改,
下载地址为:https://github.com/data-science-z/ascii_art/tree/Update
代码如下:
from ascii_art import ASCIIArt, ASCIIPicture
picture = ASCIIArt('gao.jpg', 5).draw_ascii(curve=1)#更改参数值,调节清晰度
ASCIIPicture(picture).save('gao_crow1.png')
#彩色图片
colored_picture = ASCIIArt('gao.jpg', 5).draw_color_ascii(ASCIIArt.FULL_RANGE, curve=1.5)
ASCIIPicture(colored_picture).save('gao_crow2.png')
