day54——Python 处理图片

Python 处理图片

PIL 是 Python 最常用的图像处理库,在 Python 2.x 中是 PIL 模块,在 Python 3.x 中已经替换成 pillow 模块,安装 PIL :pip install pillow

1、Python 查看图片的一些属性

1 #!/usr/bin/env python
2 #-*- coding:utf-8 -*-
3 
4 from PIL import Image
5 
6 image = Image.open("dora.jpg")    # 打开一个图片对象
7 print(image.format)               # 查看图片的格式,结果为'JPEG'
8 print(image.size)                 # 查看图片的大小,结果为(800,450)分别表示宽和高的像素
9 print(image.mode)                 # 查看图片的模式,结果为'RGB',其他模式还有位图模式、灰度模式、双色调模式等等

2、Python 调整图片大小

1 #!/usr/bin/env python
2 #-*- coding:utf-8 -*-
3 
4 from PIL import Image
5 
6 image = Image.open("dora.jpg")    # 打开一个图片对象
7 out = image.resize((128, 128))    # 把图片调整为宽128像素,高128像素 
8 out.show()                        # 查看图片

效果图:

3、Python 旋转图片

 

1 #!/usr/bin/env python
2 #-*- coding:utf-8 -*-
3 
4 from PIL import Image
5 
6 image = Image.open("dora.jpg")    # 打开一个图片对象
7 out = image.rotate(45)            # 将图片逆时针旋转45度
8 out.show()                        # 查看图片

效果图:

 

4、Python 翻转图片

 

1 #!/usr/bin/env python
2 #-*- coding:utf-8 -*-
3 
4 from PIL import Image
5 
6 image = Image.open("dora.jpg")                  # 打开一个图片对象
7 out = image.transpose(Image.FLIP_LEFT_RIGHT)    # 左右翻转图片,如果要上下翻转参数为'Image.FLIP_TOP_BOTTOM'
8 out.show()                                      # 查看图片

效果图:

 

 

转载于:https://www.cnblogs.com/yangjinbiao/p/8320534.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值