linux下django使用imagefield需要的配置

我的环境:centos / Python2.5

PIL是python理想的图片处理module,但是想要良好的支持各种图片,还需要检查一下几步,否则会提示:IOError: decoder jpeg not available之类的。

第一步:安装zlib png freetype jpeg

install zlib (官方源没有zlib,别想yum了)
下载zlib,(zlib.net已墙,可以去SF.net),

url:http://sourceforge.net/projects/libpng/files/zlib/1.2.5/zlib-1.2.5.tar.gz/download?use_mirror=superb-dca2

wget http://zlib.net/zlib-1.2.7.tar.gz

shell:

$ tar -xvzf zlib-1.2.5.tar.gz
$ cd zlib-1.2.5
$ ./configure –prefix=/usr/local
$ make
$ sudo make install
install png(忘记yum吧) 用到再安装就可以了
shell:
$ wget ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng-1.5.6.tar.gz
$ tar -xvzf libpng-1.5.6.tar.gz
$ cd libpng-1.5.6
$ ./configure –prefix=/usr/local
$ make
$ sudo make install

install freetype(忘记yum吧)
shell:

$ wget http://nchc.dl.sourceforge.net/project/freetype/freetype2/2.4.7/freetype-2.4.7.tar.gz
$ tar -jxf freetype-2.4.7.tar.gz
$ cd freetype-2.4.7/
$ ./configure –prefix=/usr/local
$ make
$ make install

install jpeg(忘记yum吧)
shell:

$ wget http://www.ijg.org/files/jpegsrc.v8c.tar.gz
$ tar -xvzf jpegsrc.v8c.tar.gz
$ cd jpeg-8c/
$ ./configure –prefix=/usr/local
$ make
$ sudo make install

第三步:安装PIL(Python Imaging Library )

 

shell 写道 我装的是1.6

pil下载: http://effbot.org/downloads/Imaging-1.1.6.tar.gz

http://effbot.org/downloads/Imaging-1.1.7.tar.gz

$ wget http://effbot.org/downloads/Imaging-1.1.6.tar.gz
$ tar -xvzf Imaging-1.1.6.tar.gz
$ cd Imaging-1.1.6/
修改setup.py文件:
$ vim nano 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
$ 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,搞定!

 

 

报错:

python2.6 seccode.py
Traceback (most recent call last):
File “seccode.py”, line 81, in <module>
frame = getframe(‘test.gif’)
File “seccode.py”, line 40, in getframe
im = Image.open(fname)
File “/data1/python2.6/lib/python2.6/site-packages/PIL/Image.py”, line 1901, in open
return factory(fp, filename)
File “/data1/python2.6/lib/python2.6/site-packages/PIL/ImageFile.py”, line 82, in __init__
self._open()
File “/data1/python2.6/lib/python2.6/site-packages/PIL/GifImagePlugin.py”, line 97, in _open
self.seek(0) # get ready to read first frame
File “/data1/python2.6/lib/python2.6/site-packages/PIL/GifImagePlugin.py”, line 152, in seek
self.dispose = Image.core.fill(“P”, self.size,
File “/data1/python2.6/lib/python2.6/site-packages/PIL/Image.py”, line 36, in __getattr__
raise ImportError(“The _imaging C module is not installed”)
ImportError: The _imaging C module is not installed

处理方法:命令行下执行,因为jpeg的解析so文件在/usr/local/lib下面,所以要把动态库的链接路径加到环境变量里就OK了

export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

#vi /etc/profile
在里面加入:
export PATH=”$PATH:/opt/au1200_rm/build_tools/bin”

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值