Python之Python Imaging Library
document:http://effbot.org/imagingbook/pil-index.htm http://pillow.readthedocs.io/en/3.1.x/index.html
from PIL import Image
1.打开图片
img = Image.open(fileName)
2.保存图片
img.save(imgName)
3.调整图片大小
def resize(self, width, height):
o_width, o_height = img.size
o_ratio = o_width/float(o_height)
n_ratio = width/float(height)
if o_ratio > n_ratio:
re_ration = width/float(o_width)
a_height = int(re_ration*o_height)
img = self.img.resize((width,a_height),Image.ANTIALIAS)
else:
re_ration = height/float(o_height)
a_width = int(re_ration*o_width)
img = img.resize( (a_width,height),Image.ANTIALIAS)
img.save('test.jpg')
4.新建图片
img = Image.new("RGB", (width, height), "black")
5.粘贴拷
box = (100,100,500,500)#设置要拷贝的区域
region = im.crop(box)
region = region.transpose(Image.ROTATE_180)#从字面上就可以看出,先把region中的Image反转180度,然后再放回到region中。
im.paste(region, box)#粘贴box大小的region到原先的图片对象中。
Python之Python Imaging Library的更多相关文章
- Windows环境下安装PIL(Python Imaging Library)库
微信小程序--跳一跳最近火了一把,于是整了个辅助进行试玩,不过在运行程序过程中出现了个报错如图所示: 显然是缺少PIL(Python Imaging Library)库文件,于是通过pip命令行进行安 ...
- 【python】Python框架、库和软件资源大全
很多来自世界各地的程序员不求回报的写代码为别人造轮子.贡献代码.开发框架.开放源代码使得分散在世界各地的程序员们都能够贡献他们的代码与创新. Python就是这样一门受到全世界各地开源社区支持的语言. ...
- Embeding Python & Extending Python with FFPython
Introduction ffpython is a C++ lib, which is to simplify tasks that embed Python and extend Python. ...
- Python:Python 3.x 的革新
Python 3.x 版本在设计时为了向最好的语言前进,没有考虑向下兼容,许多针对早期 Python 版本设计的程序都无法正常运行.本文简单介绍了 Python 3.x 版本较之 2.x 版本语法上的 ...
- Awesome Python,Python的框架集合
Awesome Python A curated list of awesome Python frameworks, libraries and software. Inspired by awes ...
- 【Python】Python 网页爬虫 & 文本处理 & 科学计算 & 机器学习 & 数据挖掘兵器谱
本文转载自:https://www.cnblogs.com/colipso/p/4284510.html 好文 mark http://www.52nlp.cn/python-%E7%BD%91%E9 ...
- python之Python内置函数一览表
Python 解释器自带的函数叫做内置函数,这些函数可以直接使用,不需要导入某个模块. 如果你熟悉 Shell 编程,了解什么是 Shell 内置命令,那么你也很容易理解什么是 Python 内置函数 ...
- 1 python学习——python环境配置
1 python学习--python环境配置 要学习python语言,光看书看教程还是不好,得动手去写.当然,不管学习什么编程语言,最佳的方式还在于实践. 要实践,先得有一个Python解释器来解释执 ...
- CentOS使用virtualenv搭建独立的Python环境-python虚拟环境
CentOS使用virtualenv搭建独立的Python环境-python虚拟环境 virtualenv可以搭建虚拟且独立的python环境,可以使每个项目环境与其他项目独立开来,保持环境的干净,解 ...
- python 运行python manege.py runserver时报错:“no module named djangorestframework” 的解决方案
python 运行python manege.py runserver时报错:“no module named djangorestframework” 的解决方案 importerror:no mo ...
随机推荐
- .git文件过大!删除大文件
在我们日常使用Git的时候,一般比较小的项目,我们可能不会注意到.git 这个文件. 其实, .git文件主要用来记录每次提交的变动,当我们的项目越来越大的时候,我们发现 .git文件越来越大. 很大 ...
- Windows Self Signed Driver
In particular, Microsoft® instituted a device driver certification process for its Windows® desktop ...
- Codeforces Good Bye 2015 A. New Year and Days 水题
A. New Year and Days 题目连接: http://www.codeforces.com/contest/611/problem/A Description Today is Wedn ...
- C# GDI在控件上绘图
本文以以在chart控件上和窗体上画矩形为例子 不多解释了,代码很简单. 还有一些童鞋要别的源码,给我发邮箱吧 using System; using System.Collections.Gener ...
- Eclipse中SVN的安装步骤(两种)和用法
一.给安装EclipseSVN,最常见的有两种方式:手动方式和使用安装向导方式.详细过程例如以下: 方式一:手动安装 1.从官网下载site-1.6.9.zip文件,网址是:subclipse.tig ...
- defer和async的区别
先来试个一句话解释仨,当浏览器碰到 script 脚本的时候: <script src="script.js"></script> 没有 defer 或 a ...
- 安装linux系统并配置那点事
安装完成后,将看到如下控制台: 输入以上安装信息中所填写的用户名(user),随后输入密码(user),即可登录 Ubuntu. 随时可使用 Ctrl + Alt 快捷键可离开虚拟机. 3 配置 Ub ...
- 剑指 offer set 6 打印从 1 到 N 的所有数
总结 1. 求全排列的变形题, 有些隐晦, 没看出来
- LMAX Disruptor – High Performance, Low Latency and Simple Too 转载
原文地址:http://www.symphonious.net/2011/07/11/lmax-disruptor-high-performance-low-latency-and-simple-to ...
- Linux根文件系统的制作
转载:http://www.cnblogs.com/hnrainll/archive/2011/06/09/2076655.html 1. 根文件系统 文件系统是包括在一个磁盘(包括光盘.软盘.闪盘及 ...