PIL 图像字符画绘制
from PIL import Image ascii_char = list('"$%_&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\|()1{}[]?-/+@<>i!;:,\^`.') def get_char(r,g,b,alpha = ):
if alpha == :
return ' '
gray = int(0.2126*r+0.715*g+0.0722*b)
unit = /len(ascii_char)
return ascii_char[int(gray//unit)] def main():
file = input()
im = Image.open(file) assert isinstance(im, Image.Image) W,H = ,
im = im.resize((W,H)) txt = ""
fo = open("pic_char.txt","w") for i in range(H):
txt=""
for j in range(W):
r,g,b = im.getpixel((j,i))
txt += get_char(r,g,b)
txt+='\n'
fo.write(txt)
fo.close()
main()
PIL第三方类库,无代码提示
assert isinstance(im, Image.Image)
PIL 图像字符画绘制的更多相关文章
- 使用Pillow(PIL)库实现中文字符画
上班摸鱼写的,不多说了,直接上脚本 #coding=utf-8 from PIL import Image from PIL import ImageDraw from PIL import Imag ...
- python图像、视频转字符画
python图像转字符画需要用到matplotlib.pyplot库,视频转字符画需要用到opencv库,这里的代码基于python 3.5 图像转字符画需要先将图像转为灰度图,转灰度图的公式是 gr ...
- Swift 实现图片转字符画的功能
本文介绍一个IOS APP , 将图片转换成ASCII字符画,使用Swift语言编写. 举个例子,我们使用著名的蕾娜照片作为原图片 经APP转换后形成的字符画,我们打印出来,效果如下: 放大她的脸部可 ...
- 用函数式的 Swift 实现图片转字符画的功能
今天整理 Pocket 中待看的文章,看到这篇<Creating ASCII art in functional Swift>,讲解如何用 Swift 将图片转成 ASCII 字符.具体原 ...
- Python 图片转字符画
Python 图片转字符画 一.课程介绍 1. 课程来源 原创 2. 内容简介 本课程讲述怎样使用 Python 将图片转为字符画 3. 前置课程 Python编程语言 Linux 基础入门(新版) ...
- 图片处理拓展篇 : 图片转字符画(ascii)
首先要明确思路, 图片是由像素组成的, 不同的像素有不同的颜色(rgb), 那么既然我们要转化为字符画, 最直接的办法就是利用字符串来替代像素, 也就是用不同的字符串来代表不同的像素. 另外图片一般来 ...
- python学习---50行代码实现图片转字符画2
from PIL import Image codeLib = '''@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\|()1{}[]?-_+~<> ...
- python小项目(-)图片转字符画
# -*- coding: utf-8 -*- from PIL import Image codeLib = '''@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrj ...
- 将图片转为ASCII字符画
原文:将图片转为ASCII字符画 Copyright 2012 Conmajia 源代码下载:点击这里 什么是字符画?就是用ASCII字符来近似组成图像,就像这样: ╭╮ ╭╮ ││ ││ ╭┴┴—— ...
随机推荐
- Git本地缓存问题 修改密码后git无法拉取
问题描述:使用正确的用户名和密码可以登录到Git代码仓库,但是在本地无法使用Git bash命令行的方式拉取代码. 问题原因:第一次使用Git bash方式拉取代码时,会根据当前的用户和密码生成一串. ...
- spring IoC源码分析 (3)Resource解析
引自 spring IoC源码分析 (3)Resource解析 定义好了Resource之后,看到XmlFactoryBean的构造函数 public XmlBeanFactory(Resource ...
- C++11并发编程:async,future,packaged_task,promise
一:async std::async:用于创建异步任务,可以代替创建线程,函数原型:async(std::launch::async | std::launch::deferred, f, args. ...
- File upload error - unable to create a temporary file
php上传图片的时候会报错: File upload error - unable to create a temporary file 文件上传错误 - 无法创建一个临时文件 你只需要打开你的php ...
- Smart3D基础理论
目录: 1. Smart3D发展进程 2. 硬件要求与建模原理 3. Smart3D建模优势 4.Smart3D的应用领域 5. Smart3D的软件组成 6. Samrt3D主控台概述 1. Sma ...
- FZU 1924——死锁——————【topo判环】
死锁 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status Pr ...
- webbrowser使用已过期资源的一个报错
如果webbrowser控件已更新,仍使用一个HtmlElement就会出现以下错误: 2013-12-23 17:33:48,375 [18] ERROR xx.xxx<Run>b__0 ...
- JavaScript 监听回车事件
JS监听某个输入框 //回车事件绑定 $('#search_input').bind('keyup', function(event) { if (event.keyCode == "13& ...
- windows下快速修改host文件
windows下快速修改host文件 win+r 输入 notepad c:\Windows\System32\drivers\etc\hosts
- win10下MySQL 5.7.20解压版安装步骤
1.从官网下载MySQL5.7.20解压版64位:https://dev.mysql.com/downloads/file/?id=473309. 2.解压(我的解压路径为:E:\mysql-5.7. ...