PIL之基础应用
>>> from PIL import Image
>>> #读取图像文件
...
>>> gal=Image.open('/Users/similarface/PycharmProjects/mybook/products/2016/06/13/1_TIBX78J.png')
>>> #查看文件大小
...
>>> gal.size
(100, 100)
>>> #显示文件
...
>>> gal.show()

>>> #显示灰度图像
...
>>> gal.convert('L').show()

>>> gal.mode
'RGBA'
>>> gal.format
'PNG'
'''
将图片的格式转化成jpg格式的
'''
filelist=[]
for infile in filelist:
f, e = os.path.splitext(infile)
outfile = f + ".jpg"
if infile != outfile:
try:
Image.open(infile).save(outfile)
except IOError:
print "cannot convert", infile '''
将图片生成缩略图
'''
size = 128, 128
for infile in sys.argv[1:]:
outfile = os.path.splitext(infile)[0] + ".thumbnail"
if infile != outfile:
try:
im = Image.open(infile)
im.thumbnail(size)
im.save(outfile, "JPEG")
except IOError:
print "cannot create thumbnail for", infile
#获取文件基础消息
import Image
for infile in filelist:
try:
im = Image.open(infile)
print infile, im.format, "%dx%d" % im.size, im.mode
except IOError:
pass
'''
Cutting, Pasting and Merging Images #
''' >>> box=(0,25,70,50)
>>> region=gal.crop(box)
>>> region.show()
#存储的图片是从原始文件左上角为参照原点(0,25)开始
#70长 50高的图片 #将图片旋转180
region=region.transpose(Image.ROTATE_180)
>>> region.save('/tmp/sub.png',"PNG") def roll(image, delta):
"Roll an image sideways"
xsize, ysize = image.size delta = delta % xsize
if delta == 0:
return image
#图像裁减
part1 = image.crop((0, 0, delta, ysize))
part2 = image.crop((delta, 0, xsize, ysize))
#图像粘贴
image.paste(part2, (0, 0, xsize-delta, ysize))
image.paste(part1, (xsize-delta, 0, xsize, ysize))
return image #将颜色通道分割 [这儿是rgba的图像格式,有rgb的]
r,g,b ,a= gal.split() #合并通道
im = Image.merge("RGB", (b, g, r))
im.show()
im = Image.merge("RGB", (b, g, a)) >>> gal=Image.open('/Users/similarface/PycharmProjects/mybook/products/2016/06/13/1_TIBX78J.png')
>>>
>>> gal.resize((128,128))
<PIL.Image.Image image mode=RGBA size=128x128 at 0x108AECF90>
#重新设置大大
>>> gal.resize((1128,1128)).show()
#旋转45度
>>> gal.rotate(45).show()
#旋转30度
>>> gal.rotate(30).show() #图像左右对称图
gal.transpose(Image.FLIP_LEFT_RIGHT).show()
#图像上下对称图
gal.transpose(Image.FLIP_TOP_BOTTOM)
#图像旋转
out = im.transpose(Image.ROTATE_90)
out = im.transpose(Image.ROTATE_180)
out = im.transpose(Image.ROTATE_270)
PIL之基础应用的更多相关文章
- python之PIL模块基础功能
Image主要是打开图片后,对图片进行编辑,主要有以下一些常用功能: 1.读取并显示图片: from PIL import Image img = Image.open("H:\\salar ...
- 潭州课堂25班:Ph201805201 爬虫基础 第九课 图像处理- PIL (课堂笔记)
Python图像处理-Pillow 简介 Python传统的图像处理库PIL(Python Imaging Library ),可以说基本上是Python处理图像的标准库,功能强大,使用简单. 但是由 ...
- python爬虫基础15-python图像处理,PIL库
Python图像处理-Pillow 简介 Python传统的图像处理库PIL(Python Imaging Library ),可以说基本上是Python处理图像的标准库,功能强大,使用简单. 但是由 ...
- python之PIL库(Image模块)
PIL(Python Image Library)是python的第三方图像处理库,PIL的功能非常的强大,几乎被认定是Python的官方图像处理库了. 由于PIL仅支持到python2.7于是一群志 ...
- python 使用 PIL 和 matplotlib 获取图片像素点处理之后再写入
python 版本 3.x 首先安装 PIL 由于PIL仅支持到Python 2.7,加上年久失修,于是一群志愿者在PIL的基础上创建了兼容的版本,名字叫Pillow,支持最新Python 3.x,又 ...
- Python 3.6 -win64环境安装PIL模块
PIL:Python Imaging Library,已经是Python平台事实上的图像处理标准库了.PIL功能非常强大,但API却非常简单易用. 由于PIL仅支持到Python 2.7,加上年久失修 ...
- py库: PIL 、pillow(图像处理)
https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/0014320027235877 ...
- 五十 常用第三方模块 PIL
PIL:Python Imaging Library,已经是Python平台事实上的图像处理标准库了.PIL功能非常强大,但API却非常简单易用. 由于PIL仅支持到Python 2.7,加上年久失修 ...
- Python 学习笔记之—— PIL 库
PIL,全称 Python Imaging Library,是 Python 平台一个功能非常强大而且简单易用的图像处理库.但是,由于 PIL 仅支持到Python 2.7,加上年久失修,于是一群志愿 ...
随机推荐
- 【对询问分块】【主席树】bzoj2683 简单题
对操作序列分块,每S次暴力重建主席树. 当S=sqrt(n*log(n))时,复杂度为O(m*sqrt(n*log(n))). 在线的. #include<cstdio> #include ...
- 【线段树】bzoj3922 Karin的弹幕
设置一个值K. d<=K:建立多组线段树:d>K:暴力. 最优时间复杂度的伪计算: O(n*K*logn(建树)+m*logn(询问类型1)+m*n/K(询问类型2)+m*K*logn(修 ...
- Problem C: 零起点学算法18——3个数比较大小
#include<stdio.h> int main() { int a,b,c; while(scanf("%d %d %d",&a,&b,& ...
- 【Todo】Apache-Commons-Pool及对象池学习
有这篇文章: http://www.cnblogs.com/tommyli/p/3510095.html 方案提供了三种类型的pool,分别是GenericKeyedObjectPool,SoftRe ...
- 使用iozone测试磁盘性能(测试文件读写)
IOzone是一个文件系统测试基准工具.可以测试不同的操作系统中文件系统的读写性能.可以通过 write, re-write, read, re-read, random read, random w ...
- vue2自定义事件之$emit
父组件: API上的解释不多: https://cn.vuejs.org/v2/api/#vm-emit vm.$emit( event, […args] ) 参数: {string} event [ ...
- mybatis常用jdbcType数据类型以及对应的JavaType
1.MyBatis 通过包含的jdbcType类型 BIT.FLOAT.CHAR .TIMESTAMP . OTHER .UNDEFINEDTINYINT .REAL .VARCHAR .BINARY ...
- 阿里云ECS linux通过iptables 配置SNAT代理网关,实现局域网上网
场景说明: 本文将介绍如何通过为VPC中Linux系统的ECS实例配置SNAT,实现无公网ECS通过有EIP的服务器代理访问公网. 步骤: 1.使用SSH的方法登陆一个已经绑定EIP外网的ECS实例. ...
- 三位一体的漏洞分析方法-web应用安全测试方法
本文转自乌云知识库 0x00 前言 节选自: http://www.owasp.org.cn/OWASP_Conference/owasp-20140924/02OWASPWeb20140915.pd ...
- 我的superui开源后台bootstrap开发框架
我的superui开源后台bootstrap开发框架:http://git.oschina.net/tzhsweet/superui