Python 25行代码实现图片转字符画
来源:互联网 发布:2017程序员笔记本推荐 编辑:程序博客网 时间:2024/05/29 03:35
在网上看到许多图片转字符画的代码,自己试着写了一个简单版本
- 编译环境
- python3
- pyCharm2017.2.3
- Pillow库 4.2.1
小埋:
文件路径:
- 源代码:
from PIL import Imageascii_char = list("$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\|()1{}[]?-_+~<>i!lI;:,\"^`'. ")length = len(ascii_char)im = Image.open('sm.jpeg')im = im.resize((240, 240)) #重新调整宽高width, height = im.sizedef get_char(r, g, b, alpha=256): #RGB转为list里的字符 if alpha == 0: return ' ' gray = int(0.2126 * r + 0.7152 * g + 0.0722 * b) #RGB公式转灰度值 return ascii_char[int(gray * length / 256)]output = "" #String字符串输出for i in range(height): for j in range(width): output += get_char(*im.getpixel((j, i))) output += '\n'f = open('textPicture.txt', 'w')f.write(output)f.close()
效果图(部分):
阅读全文
0 0
- Python 25行代码实现图片转字符画
- Python 50行代码实现图片转字符画
- Python实现图片转字符画
- python 一百行代码将图片转成字符画
- Python 实现图片转换为字符画
- Python 图片转字符画
- Python 图片转字符画
- python图片转字符画
- Python 图片转字符画
- python实现图片字符转换
- python图片字符画
- python图片转字符
- python开发之图片转字符画
- 1.Python 图片转字符画
- Python 图片转字符画 学习笔记
- Python——图片转字符画
- [1]python图片转字符画
- 实现图片转字符
- 类加载机制
- Linux Shell编程入门
- Codeforces 230E Triangles【思维】
- 基于 HED网络TensorFlow 和 OpenCV 实现图片边缘检测
- openstack
- Python 25行代码实现图片转字符画
- Docker中安装OpenvSwitch 附rpm文件下载
- spring boot项目实战:redis
- Go语言 channel详解
- 工作中遇到的问题总结
- Scala(2)-类
- LeetCode#86 Partition List (week4)
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 B Coin(逆元,费马小定理)
- Dropout和Batch Normalization的差别