pillow 模块
pillow模块
图片处理
安装
pip install Pillow
对图片旋转90度显示
from PIL import Image
im=Image.open("t.jpg")
im.rotate(90).show()
对图片进行裁剪并保存
from PIL import Image
import glob, os size = 128, 128 for infile in glob.glob("*.jpg"):
file, ext = os.path.splitext(infile)
im = Image.open(infile)
im.thumbnail(size, Image.ANTIALIAS)
im.save(file + ".thumbnail.jpg", "JPEG")
切割图片
from PIL import Image def fill_image(image): width, height = image.size # 选取长和宽中较大值作为新图片的边长
new_image_length = width if width > height else height # 生成新图片[白底],底色可配置其他颜色
new_image = Image.new(image.mode, (new_image_length, new_image_length), color='white') # 将之前的图片input image 粘贴在新图上,居中
if width > height: # 原图宽大于高,则填充图片的竖直维度 #(x,y)二元组表示粘贴上图相对下图的起始位置,是个坐标点
new_image.paste(image, (0, int((new_image_length - height) / 2)))
else:
new_image.paste(image, (int((new_image_length - width) / 2), 0)) return new_image def cut_image(image): width, height = image.size item_width =int(width /3) # 因为朋友圈一行放3张图 box_list = [] for i in range(0, 3): for j in range(0, 3): box = (j*item_width, i*item_width, (j+1)*item_width, (i+1)*item_width) # (left, top, right, bottom) box_list.append(box) image_list = [image.crop(box) for box in box_list] return image_list def save_images(image_list): index = 1 for image in image_list: image.save(str(index) + '.png', 'PNG') index += 1 if __name__ == '__main__':
file_path = "t.jpg" # 把目标图片 input image 放到代码所处的文件夹里 image = Image.open(file_path)
image = fill_image(image) image_list = cut_image(image) save_images(image_list)
pillow 模块的更多相关文章
- Django 生成验证码或二维码 pillow模块
一.安装PIL PIL:Python Imaging Library,已经是Python平台事实上的图像处理标准库了.PIL功能非常强大,API也非常简单易用. PIL模块只支持到Python 2 ...
- 苹果电脑python3安装pillow模块
我刚开始在苹果电脑自带的python 中安装了pillow模块,导致在后期我想在python3中安装pilow模块的时候 pip3 install pillow 但是总会提示错误说电脑中已经存在pil ...
- Pillow模块图片生成
0825自我总结 Pillow模块图片生成 一.模块安装 pip3 install pillow 二.模块的载入 import PIL 三.django结合img标签生成图片 img.html < ...
- 图像处理pillow模块
pillow模块: -->基本的图像处理模块 Pip install pillow from PIL import Image #1.读取图片 im = Image.open('/test.jp ...
- pillow模块
pillow模块 用于操作图片的模块 安装 pip install pillow 生成验证码 from PIL import Image,ImageDraw,ImageFont from io imp ...
- (python)图片处理Pillow模块的使用
Pillow中最重要的类就是Image,该类存在于同名的模块中.可以通过以下几种方式实例化:从文件中读取图片,处理其他图片得到,或者直接创建一个图片. 还有一个类为ImageDraw,用来画图. 1. ...
- python安装pillow模块错误
安装的一些简单步骤就不介绍了,可以去搜索一下,主要就记录下我在安装pillow这一模块遇到的问题 1:安装好pillow后,安装过程没有出错 2:但是在python的IDLE输入from PIL im ...
- python pillow模块用法
pillow Pillow是PIL的一个派生分支,但如今已经发展成为比PIL本身更具活力的图像处理库.pillow可以说已经取代了PIL,将其封装成python的库(pip即可安装),且支持pytho ...
- Python笔记_第二篇_面向过程_第二部分_5.第三方模块的使用和自定模块(以Pillow模块为例)
1. 安装第三方模块: 打开黑屏终端: cmd: pip -verson pip - V C:\windows\system32>pip -V pip from c:\python37\lib\ ...
随机推荐
- Jmeter之设置动态关联
前言 在Jmeter中,如何进行接口关联(上一个接口的返回参数作为下一个接口的入参使用)测试呢?下面我们一起来学习吧! 需求:需要利用商品信息接口的返回结果skuName值作为下一个登录接口参数Use ...
- node - 简单的爬虫案例
cherrio模块 安装 cnpm install cherrio 使用方法 const cheerio = require('cheerio') const $ = cheerio.load('&l ...
- TCP三次握手四次挥手过程梳理
1. 数据传输的大致示意图 1.1 TCP数据报文首部内部 1.2 TCP连接的几种状态说明 即命令 netstat 结果中的所有状态: 2. TCP连接建立的全过程 2.1 TCP三次握手建立TCP ...
- CentOS7.3yum安装MariaDB报错[Errno 256]
在yum安装MariaDB时出现下面这个错误提示,然后着手排查,先检查了/etc/yum.repo.d/下的配置文件,没有错误. failure: repodata/repomd.xml from m ...
- 404 not found Webshell
404 not found Webshell 克隆或下载项目: git clone https://github.com/CosasDePuma/SecurityNotFound.git Securi ...
- 你们见过java类型转换,自己转自己失败的情况吗?很神奇的操作
问题就是上面这个问题. List<SlaughterProductModelForm> slaughterProducts = slaughterForm.getSlaughterProd ...
- .net core 部署到IIS 后出现 w3wp.exe 【】发生了未经处理的win32异常……
抗疫时期,想到弄个微信程序用于社区出入和复工复产人员流动登记,老早就买的盛派的书和视频,一直没时间看,趁这个需求,下载盛派weixinDSK开始学习,先是打开盛派的网站陆续无法打开, 帮助文档也没能抢 ...
- Android Studio 快捷方式记录
- C# WPF可拖拽的TabControl
微信公众号:Dotnet9,网站:Dotnet9,问题或建议:请网站留言, 如果对您有所帮助:欢迎赞赏. C# WPF可拖拽的TabControl 阅读导航 本文背景 代码实现 本文参考 源码 1. ...
- HDU-1166 敌兵布阵 (树状数组模板题——单点更新,区间求和)
题目链接 AC代码: #include<iostream> #include<cstdio> #include<cstring> #include<algor ...