PIL(Python Imaging Library)是Python经常使用的图像处理库,而Pillow是PIL的一个友好Fork,提供了了普遍的文件格式支持,强大的图像处理能力,主要包括图像储存、图像显示、格式转换以及基本的图像处理操做等。python
Pillow的文档:http://pillow.readthedocs.io/en/latest/linux
Pillow的github:https://github.com/python-pillow/Pillowgit
-----------------------------------------------------------------github
0x0. Pillow的注意事项ubuntu
Pillow and PIL cannot co-exist in the same environment. Before installing Pillow, please uninstall PIL. Pillow >= 1.0 no longer supports “import Image”. Please use “from PIL import Image” instead. Pillow >= 2.1.0 no longer supports “import _imaging”. Please use “from PIL.Image import core as _imaging” instead. Pillow < 2.0.0 supports Python versions 2.4, 2.5, 2.6, 2.7. Pillow >= 2.0.0 < 4.0.0 supports Python versions 2.6, 2.7, 3.2, 3.3, 3.4, 3.5 Pillow >= 4.0.0 supports Python versions 2.7, 3.3, 3.4, 3.5, 3.6
0x1. windows安装PILwindows
PIL安装很麻烦,推荐下载exe直接安装app
PIL官网:http://pythonware.com/products/pil/python2.7
但如今里面下载连接访问不了,我把32位和64位版本上传到博客园以供下载。ide
PILwin32:http://files.cnblogs.com/files/pcat/PILwin32.zipspa
PILwin64:http://files.cnblogs.com/files/pcat/PILwin64.zip
0x2. windows安装Pillow
pip install Pillow
或者在http://www.lfd.uci.edu/~gohlke/pythonlibs/#pillow 下载wheel文件使用pip安装
0x3. linux安装python2.七、pip
sudo apt-get install python sudo apt-get install python-pip
0x4. linux安装Pillow
在linux里安装PIL不怎么建议,依赖也多,并且会有各类报错。
kali的python默认已安装了Pillow。
在debian/ubuntu里安装Pillow:
sudo apt-get install python-imaging
或者
sudo pip install -I --no-cache-dir -v Pillow
python-imaging安装后的支持import Image
0x5. Pillow wrapper for PIL compatibility
github地址:https://github.com/yinpeng/pillow-pil
其做者是这样介绍:他项目中也使用Pillow替代了PIL,不过PIL和Pillow的import语句不兼容致使本项目代码修改倒还好说,问题是后来使用的依赖PIL的第三方组件不兼容,咱们既不想同时安装Pillow和PIL,又不想修改第三方组件的源代码,因此他写了个很简单的Pillow-PIL,使得依赖PIL的第三方组件不用修改源代码就能够使用Pillow了。安装法子以下:
pip install Pillow-PIL
0x6. PIL一些报错
ImportError:The _imagingft C module is not installed
这个是在windows里安装PIL所报错,建议直接exe安装。
PIL.Image.open() IOError: cannot identify image file
首先检查图片是否是正确的,若是各类检查过仍是有问题建议重装PIL
0x7. Pillow报KeyError问题
python >>> import Image >>> Image.init() 1 >>> Image.SAVE.keys() ['PCX', 'HDF5', 'EPS', 'MSP', 'XBM', 'WEBP', 'BUFR', 'PPM', 'BMP', 'TGA', 'ICO', 'TIFF', 'JPEG', 'SPIDER', 'GIF', 'GRIB', 'IM', 'FITS', 'PDF', 'WMF', 'MPO', 'PALM', 'JPEG2000', 'PNG']