安装pillow

pillow的文档页面,documentation of Pillow

生成一个有单一颜色的图像

from PIL import Image, ImageDraw
img = Image.new(mode, size, color)
img.save(filename)

There are various values for mode listed in the documentation of Pillow. For example RGB and RGBA can be modes. The size is a tuple in the form of (width, height) in pixels. The color can be a word such as 'red', or a triplet for RGB colors of 3 values between 0-255.

例子

from PIL import Image

img = Image.new('RGB', (60, 30), color = 'red')
img.save('pil_red.png')

使用RGB三个数值创建颜色

from PIL import Image

img = Image.new('RGB', (60, 30), color = (73, 109, 137))
img.save('pil_color.png')

在图像上写字

from PIL import Image, ImageDraw

img = Image.new('RGB', (100, 30), color = (73, 109, 137))

d = ImageDraw.Draw(img)
d.text((10,10), "Hello World", fill=(255,255,0)) img.save('pil_text.png')

换不同的字体

There are a number of ways to select the font used for writing on the image. We need to import and use the ImageFont to load a TrueType font. Mac OSX supplies a bunch of fonts that are located in the /Library/Fonts/. On other platforms you'll need to locate the files yourself and then pass the full path to the function. Alternatively you could include the font-file in your application and then you can know where is the font-file relative to your code.

In this example we load the font using the truetype method of the ImageFont passing to it the path to the fonts and the size of the fonts to be loaded.

from PIL import Image, ImageDraw, ImageFont

img = Image.new('RGB', (100, 30), color = (73, 109, 137))

fnt = ImageFont.truetype('/Library/Fonts/Arial.ttf', 15)
d = ImageDraw.Draw(img)
d.text((10,10), "Hello world", font=fnt, fill=(255, 255, 0)) img.save('pil_text_font.png')

python图像处理库Pillow基本使用方法的更多相关文章

  1. Python图像处理库Pillow常用使用方法

    PIL(Python Imaging Library)是Python一个强大方便的图像处理库,只支持到Python2.7.Pillow是PIL的一个派生分支,在Python3中用Pillow代替PIL ...

  2. Python图像处理库Pillow入门

    http://python.jobbole.com/84956/ Pillow是Python里的图像处理库(PIL:Python Image Library),提供了了广泛的文件格式支持,强大的图像处 ...

  3. python第三方库-图像处理库pillow

    python图像处理库pillow 安装 pip install pillow 使用 导入 from PIL import pillow 读取图像 picture = Image.open('test ...

  4. Python图像处理库:Pillow 初级教程

    Python图像处理库:Pillow 初级教程 2014-09-14 翻译 http://pillow.readthedocs.org/en/latest/handbook/tutorial.html ...

  5. Python图像处理库:PIL中Image,ImageDraw等基本模块介绍

    Python图像处理库:PIL中Image,ImageDraw等基本模块介绍 标签: 图像处理PILPYTHON 2016-08-19 10:58 461人阅读 评论(0) 收藏 举报  分类: 其他 ...

  6. Python图像处理库PIL中图像格式转换(一)

    在数字图像处理中,针对不同的图像格式有其特定的处理算法. 所以,在做图像处理之前,我们须要考虑清楚自己要基于哪种格式的图像进行算法设计及事实上现.本文基于这个需求.使用python中的图像处理库PIL ...

  7. Python图像处理库(1)

    转自:http://www.ituring.com.cn/tupubarticle/2024 第 1 章 基本的图像操作和处理 本章讲解操作和处理图像的基础知识,将通过大量示例介绍处理图像所需的 Py ...

  8. Python图像处理库——PIL

    PIL全称Python Image Library,是python官方的图像处理库,包含各种图像处理模块.Pillow是PIL的一个派生分支,包含与PIL相同的功能,并且更灵活.python3.0之后 ...

  9. Python图像处理库PIL中图像格式转换

    o 在数字图像处理中,针对不同的图像格式有其特定的处理算法.所以,在做图像处理之前,我们需要考虑清楚自己要基于哪种格式的图像进行算法设计及其实现.本文基于这个需求,使用python中的图像处理库PIL ...

随机推荐

  1. Windows删除文件夹下的指定格式文件(递归删除)

    问题描述: 今天遇到一个需求,需要对文件夹进行文件筛选.目录结构较为复杂(目录较多,层次较深),数据量较大(总共60GB左右). 鉴于上述情况,直接排除了人工处理方式(否则小伙伴们会打死我的). 解决 ...

  2. C#中各种Lock的速度比较

    简单写了个小程序,比较了一下C#中各种Lock的速度(前提是都没有进入wait状态). 各进入离开Lock 1kw次,结果如下: Lock Time (ms) No lock 58 CriticalS ...

  3. mysql 更新与查询(排序 分组 链接查询)

    UPDATE更新 #每一次数据的更新都需要update UPDATE 命令修改 MySQL 数据表数据的通用 SQL 语法: UPDATE table_name SET field1=new-valu ...

  4. 线程池不允许使用Executors去创建,而是通过ThreadPoolExecutor的方式

    1. 通过Executors创建线程池的弊端 在创建线程池的时候,大部分人还是会选择使用Executors去创建. 下面是创建定长线程池(FixedThreadPool)的一个例子,严格来说,当使用如 ...

  5. dp --- 二维dp + 最大上升子序列

    <传送门> 滑雪 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 74477   Accepted: 27574 ...

  6. Mysql 索引基础

    [1]什么是索引?为什么要建立索引? 索引,其实就是目录. 索引,用于快速找出在某个列中有某个特定值的行. 不使用索引,MySQL必须从第一条记录开始查找整张表,直到找出相关的行,那么表越大,查询数据 ...

  7. Tkint中Label&Button&Scale的使用

    top.geometry()设定窗口的初始大小 scale.set()设定滑块的初始值 scale.get()获取滑块变化的值 控件通过回调函数与其他控件进行通信(Label控件中的文本会受到Scal ...

  8. 深度学习-InfoGAN论文理解笔记

    在弄清楚InfoGAN之前,可以先理解一下变分推断目的以及在概率论中的应用与ELBO是什么,以及KL散度 https://blog.csdn.net/qy20115549/article/detail ...

  9. golang微服务框架go-micro 入门笔记2.2 micro工具之微应用利器micro web

    micro web micro 功能非常强大,本文将详细阐述micro web 命令行的功能 阅读本文前你可能需要进行如下知识储备 golang分布式微服务框架go-micro 入门笔记1:搭建go- ...

  10. 2. Spark GraphX解析

    2.1 存储模式 2.1.1 图存储模式 巨型图的存储总体上有边分割和点分割两种存储方式 1)边分割(Edge-Cut):每个顶点都存储一次,但有的边会被打断分到两台机器上.这样做的好处是节省存储空间 ...