Python图片转字符画
PIL安装很麻烦,推荐下载exe直接安装
PIL官网:http://pythonware.com/products/pil/
但现在里面下载链接访问不了,我把32位和64位版本上传到博客园以供下载
PILwin32:http://files.cnblogs.com/files/pcat/PILwin32.zip
PILwin64:http://files.cnblogs.com/files/pcat/PILwin64.zip
#coding=utf-8
from PIL.Image import Image
import argparse #命令行输入参数处理
parser=argparse.ArgumentParser() parser.add_argument('file') #输入文件
parser.add_argument('-o','--output')
parser.add_argument('--width',type=int,default=80)
parser.add_argument('--heigth',type=int,default=80) args=parser.parse_args() IMG=args.file
WIDTH=args.width
HEIGHT=args.heigth
OUTPUT=args.output ascii_char = list("$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\|()1{}[]?-_+~<>i!lI;:,\"^`'. ") #将256灰度映射到70个字符上 def get_char(r,g,b,alpha=256):
if alpha==0:
return ' '
length=len(ascii_char)
gray=int(0.2126 * r + 0.7152 * g + 0.0722 * b) unit=(256.0+1)/length
return ascii_char[int(gray/unit)] im = Image.open(IMG)
im = im.resize((WIDTH,HEIGHT), Image.NEAREST) txt="" for i in range(HEIGHT):
for j in range(WIDTH):
txt+=get_char(*im.getpixel((j,i))) print txt #字符画输出文件
if OUTPUT:
with open(OUTPUT,'w') as f:
f.write(txt)
else:
with open("output.txt",'w') as f:
f.write(txt) 链接:https://www.shiyanlou.com/courses/370/labs/1191/document
Python图片转字符画的更多相关文章
- Python 图片转字符画
Python 图片转字符画 一.课程介绍 1. 课程来源 原创 2. 内容简介 本课程讲述怎样使用 Python 将图片转为字符画 3. 前置课程 Python编程语言 Linux 基础入门(新版) ...
- Python 图片转字符画 学习笔记
Python 图片转字符画 学习笔记 标签(空格分隔): Python 声明:此文章和所有代码是学习笔记,非原创,原文教程地址:https://www.shiyanlou.com/courses/37 ...
- [笔记] Python 图片转字符画
一.介绍 用Python 代码完成图片转字符画 二.python 环境 Python 3.6.6 pillow 5.1.0 Python 图像处理库, 需要另外安装 三.原理 gray = 0.21 ...
- python图片转字符画(转)
先上代码: from PIL import Image import argparse #命令行输入参数处理 parser = argparse.ArgumentParser() parser.add ...
- 教程,Python图片转字符堆叠图
Python 图片转字符画 一.实验说明 1. 环境登录 无需密码自动登录, 2. 环境介绍 本实验环境采用带桌面的UbuntuLinux环境,实验中会用到桌面上的程序: LX终端(LXTermina ...
- 使用Python生成ASCII字符画
使用Python生成ASCII字符画 在很多的网站主页中或者程序的注释中会有一些好看的字符注释画.显得很牛逼的样子 例如: 知乎 _____ _____ _____ _____ /\ \ /\ \ / ...
- python学习---50行代码实现图片转字符画2
from PIL import Image codeLib = '''@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\|()1{}[]?-_+~<> ...
- python学习---50行代码实现图片转字符画1
转自:https://blog.csdn.net/mm1030533738/article/details/78447714 项目链接: https://www.shiyanlou.com/cours ...
- 20个python项目--图片转字符画
转自实验楼:https://www.shiyanlou.com/courses/370/learning/?id=1191 代码: # -*- coding:utf-8 -*- from PIL im ...
随机推荐
- Juniper
Juniper Networks[编辑] Juniper Networks 公司类型 上市(NYSE:JNPR) 成立 1996年2月 代表人物 执行长:Shaygan Kheradpir技术 ...
- while for if ---语句和编写计划任务
关于while循环: while do done 例如 1.关于内存的实时操作: (1).vim a.sh (2).输入以下while循环 (3)../a.sh执行脚本 2.自加一的操作: (1).v ...
- input预览上传图片
html代码 <input type="file" name="file" id="file" > <img src=&q ...
- LeetCode OJ:Longest Palindromic Substring(最长的回文字串)
Given a string S, find the longest palindromic substring in S. You may assume that the maximum lengt ...
- js的作用是临时修改 表单Action提交的地址,因为 又有新的动作需要把表单参数提交到 新的servlet中,这点很重要
JavaScript可以临时修稿 form表单的提交地址
- S2SH框架中的无刷新验证码功能实现
暑假期间在实验室做使用S2SH框架的项目,其中登录和注册需要验证码,实现了一个没有实现刷新验证码功能的简单版本,代码如下: 1 package com.sem.action; 2 3 import j ...
- Java虚拟机运行时数据区域划分
Java虚拟机数据运行时区域 方法区(Method Area) 存储加载的类信息,常量,静态变量,编译器编译后的代码等数据.虽然JVM规范把方法区描述为堆的一个逻辑部分,但它却有一个别名叫做N ...
- 前端之JavaScript再次补充(干死!!)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 【MFC】MFC中窗口重绘
MFC中窗口重绘 摘自:http://blog.csdn.net/shuilan0066/article/details/5859057 在刷新窗口时经常要调用重绘函数 MFC提供了三个函数用于窗口重 ...
- easyui1.4 汉化出问题
easyui 1.4 的textbox 验证汉化不了,需要在easyui-lang-zh_CN.js 加入 if ($.fn.textbox){ $.fn.textbox.defaults.missi ...