1.先看一段英文代码The Python Imaging Library (PIL) adds image processing capabilities to your Python interpreter. This library supports many file formats, and provides powerful image processing and graphics capabilities,意思是说PIL给Python增加了图像处理功能,这个库可以处理多种文件格式图像,提供了强大的图像处理和图形处理能力。

2.安装PIL,目前一般的PIL版本只支持python2.x版本,如果想用3.0以后的,先下载anaconda这个平台,使用起来分方便,自带spyder和qtpython插件,下载地址见https://repo.continuum.io/archive/,里面有各种平台的安装包,根据你的平台具体下载,这个平台安装好后可以很方便下载很多python支持库,本人用的Anaconda3这个版本系列。

3.这个PIL使用起来很精单首先导入模块:from PIL import Image,并查看模块内容,里面有好多组件,Image就是一个常用组件

from PIL import Image
dir(PIL)
Out[17]:
['BmpImagePlugin',
'GifImagePlugin',
'GimpGradientFile',
'GimpPaletteFile',
'Image',
'ImageChops',
'ImageColor',
'ImageEnhance',
'ImageFile',
'ImageFilter',
'ImageMode',
'ImagePalette',
'ImageSequence',
'ImageStat',
'JpegImagePlugin',
'JpegPresets',
'PILLOW_VERSION',
'PaletteFile',
'PngImagePlugin',
'PpmImagePlugin',
'TiffImagePlugin',
'TiffTags',
'VERSION',
'__builtins__',
'__cached__',
'__doc__',
'__file__',
'__loader__',
'__name__',
'__package__',
'__path__',
'__spec__',
'__version__',
'_binary',
'_imaging',
'_plugins',
'_util',
'version']

3.打开一幅图像:open(fp, mode="r")第一个参数为文件路径,第二个为打开模式一般默认只读

img = Image.open('girl1.jpg')

4.将打开的图像显示出来调用:show(self, title=None, command=None),      On Windows, it saves the image to a temporary BMP file, and usesthe standard BMP display utility to show it (usually Paint).:param title: Optional title to use for the image window,where possible.:param command: command used to show the image,一般会产生一幅临时图像,然后调用默认的图像查看器显示图像

img.show()

5.查看图像尺寸img.size

w,h = img.size

w
Out[27]: 1920

h
Out[28]: 1080

6.缩放图像img:thumbnail(self, size, resample=BICUBIC),第二个参数是缩放尺寸,第三个参数可以指定缩放模式,有`PIL.Image.NEAREST`, `PIL.Image.BILINEAR`,`PIL.Image.BICUBIC`, `PIL.Image.LANCZOS`.这四种模式

In:img.thumbnail((w/2,h/2))
In:img.size
Out[33]: (960, 540)

7.保存图像save(self, fp, format=None, **params)

img.save('D:\\girl.jpeg','jpeg')

8.根据所给的模式和尺寸创建一幅新图像new(mode, size, color=0),模式,尺寸,颜色

9.选中图片一部分进行复制crop(self, box=None) The crop rectangle, as a (left, upper, right, lower)-第二个参数为一个矩形也就是一个四个元素的元组

10.粘贴图像paste(self, im, box=None, mask=None)

最新文章

  1. java实现支付宝接口--文档..转载
  2. 【Bootstrap Demo】入门例子创建
  3. asp.net静态变量的生命周期和线程安全
  4. java-7311练习(上)
  5. 【leetcode】Maximum Gap(hard)★
  6. Leetcode 119 Pascal's Triangle II 数论递推
  7. eclipse debug小技巧
  8. TQ210裸机编程(2)——LED流水灯
  9. 利用WITH AS 优化FILTER
  10. android中的margin和padding
  11. (转)Linux下apache限速和限制同一IP连接数的实现
  12. c#类和结构体的关系
  13. c++之 常用类型
  14. Python处理海量手机号码
  15. winform WebBrowser控件中,cs后台代码执行动态生成的js
  16. ADB——命令大全
  17. uva-757-贪心
  18. Docker-常用命令(7)
  19. Java日志框架-logback的介绍及配置使用方法(纯Java工程)(转)
  20. Nginx——使用 Nginx 提升网站访问速度【转载+整理】

热门文章

  1. 33.APP后端处理视频的方案
  2. 使用jekyll和Github搭建个人博客
  3. python3 [爬虫实战] selenium 爬取安居客
  4. sql复杂案例
  5. BZOJ_3675_[Apio2014]序列分割_斜率优化
  6. BZOJ_2662_[BeiJing wc2012]冻结_分层图最短路
  7. 《The java.util.concurrent Synchronizer Framework》 JUC同步器框架(AQS框架)原文翻译
  8. Android P Beta发布!最新版本抢先体验!
  9. java中的数组二分法
  10. Error Code: 1044. Access denied for user 'root'@'%' to database