PIL是python理想的图片处理module,但是想要良好的支持各种图片,还需要检查一下几个步骤,否则会提示:IOError:decoder jpeg not avilable之类的
第一步:安装zlib png freetype jpeg
1.install zlib
下载zlib,地址:http://blog.wandahai.com/static/source/zlib-1.2.5.tar.gz
$ tar -xvzf zlib-1.2.5.tar.gz $ cd zlib-1.2.5 $ ./configure --prefix=/usr/local $ make $ make install
2.install png
下载png,地址:http://blog.wandahai.com/static/source/libpng-1.5.22.tar.gz
$ tar -xvzf libpng-1.5.6.tar.gz $ cd libpng-1.5.6 $ ./configure --prefix=/usr/local $ make $ make install
3.install freetype
下载freetype,地址:http://blog.wandahai.com/static/source/freetype-2.4.7.tar.gz
$ tar -xvzf freetype-2.4.7.tar.gz $ cd freetype-2.4.7/ $ ./configure --prefix=/usr/local $ make $ make install
4.install jpeg
下载jpeg,地址:http://blog.wandahai.com/static/source/jpegsrc.v8c.tar.gz
$ tar -xvzf jpegsrc.v8c.tar.gz $ cd jpeg-8c/ $ ./configure --prefix=/usr/local $ make $ make install
第二步:安装需要的devel库
$ apt-get install libjpeg8-dev $ apt-get install libpng12-dev $ apt-get install libfreetype6-dev $ apt-get install zlib1g-dev
第三部:安装PIL
下载Imaging,地址:http://blog.wandahai.com/static/source/Imaging-1.1.7.tar.gz
$ tar -xvzf Imaging-1.1.7.tar.gz $ cd Imaging-1.1.7/ $ vim setup.py 修改如下: JPEG_ROOT = "/usr/local/lib" ZLIB_ROOT = "/usr/local/lib" FREETYPE_ROOT = "/usr/local/lib"
检查是否支持:
$ python setup.py build_ext -i running build_ext -------------------------------------------------------------------- PIL 1.1.7 SETUP SUMMARY -------------------------------------------------------------------- version 1.1.7 platform linux2 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53) [GCC 4.5.2] -------------------------------------------------------------------- *** TKINTER support not available --- JPEG support available -----------------------> OK! --- ZLIB (PNG/ZIP) support available -----------------------> OK! --- FREETYPE2 support available -----------------------> OK! *** LITTLECMS support not available -------------------------------------------------------------------- To add a missing option, make sure you have the required library, and set the corresponding ROOT variable in the setup.py script. To check the build, run the selftest.py script.
正式安装:
$ python setup.py build $ python setup.py install
最后:
$ echo '/usr/local/lib' >> /etc/ld.so.conf $ ldconfig
最后一步:验证
#!/usr/bin/env python # -*- coding:utf-8 -*- import Image picPath = '~/images/1212.jpg' im = Image.open(picPath) print im.getbbox()
输出结果图片:
(0, 0, 600, 715)