PIL是python理想的圖片處理module,可是想要良好的支持各類圖片,還須要檢查一下幾步,不然會提示:IOError: decoder jpeg not available之類的。 python
個人環境:Linux mint 11 amd64 / Python2.7 linux
第一步:安裝zlib png freetype jpeg shell
- install zlib (ubuntu 官方源沒有zlib,別想apt-get了)
下載zlib,(zlib.net已牆,能夠去SF.net),url:http://sourceforge.net/projects/libpng/files/zlib/1.2.8/zlib-1.2.8.tar.gz ubuntu
shell: ui
$ tar -xvzf zlib-1.2.8.tar.gz
$ cd zlib-1.2.8
$ ./configure --prefix=/usr/local
$ make
$ sudo make install
shell:
$ wget ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng16/libpng-1.6.6.tar.gz (若是文件不存在就瀏覽 /src/目錄查找一下最新版)
$ tar -xvzf libpng-1.6.6.tar.gz
$ cd libpng-1.6.6
$ ./configure --prefix=/usr/local
$ make
$ sudo make install
- install freetype (忘記apt-get吧)
shell: url
$ wget http://nchc.dl.sourceforge.net/project/freetype/freetype2/2.4.11/freetype-2.4.11.tar.gz
$ tar -xvzf freetype-2.4.11.tar.gz
$ cd freetype-2.4.11/
$ ./configure --prefix=/usr/local
$ make
$ make install
- install jpeg (忘記apt-get吧)
shell: spa
$ wget http://www.ijg.org/files/jpegsrc.v9.tar.gz
$ tar -xvzf jpegsrc.v9.tar.gz
$ cd jpeg-v9/
$ ./configure --prefix=/usr/local
$ make
$ sudo make install
第二步:安裝須要的 devel庫(如今是想起apt-get的時候了) .net
shell:
$ sudo apt-get install libjpeg8-dev
$ sudo apt-get install libpng12-dev
$ sudo apt-get install libfreetype6-dev
$ sudo apt-get install zlib1g-dev
第三步:安裝 PIL( Python Imaging Library ) code
shell 寫道
$ wget http://effbot.org/downloads/Imaging-1.1.7.tar.gz
$ tar -xvzf Imaging-1.1.7.tar.gz
$ cd Imaging-1.1.7/
修改setup.py文件:
$ nano setup.py
修改以下:
JPEG_ROOT = "/usr/local/lib"
ZLIB_ROOT = "/usr/local/lib"
FREETYPE_ROOT = "/usr/local/lib"
檢查是否支持: orm
$ 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
$ sudo python setup.py install
最後一步:驗證
Python代碼
- #!/usr/bin/env python
- # -*- coding:utf-8 -*-
-
- import Image
- picPath = '~/images/1212.jpg'
-
- im = Image.open(picPath)
- print im.getbbox()
輸出結果圖片尺寸:
(0, 0, 600, 715)
yeah,搞定!