Windows x64下使用PIL并支持JPEG、PNG

  由于有任务需要用到图像处理,当然首先想到的是OpenCV,但是这次想换一种解决方案,使用Python+PIL来处理。

  然而Python标准库是不含PIL的,PIL是PythonWare公司的一个第三方Python库,在win平台上使用还有点麻烦,Google到的解决方案大都是LInux平台的,但是Linux平台上本来软件就好管理一些,而且Linux也确实适合开发,但是今天在Win下,难得麻烦转到Linux下去了,越是就开始倒腾起来。

  首先,在PIL的官网 www.pythonware.com/products/pil/‎ 上只有win32的安装程序和一个源码,看来就只有走“自己编译源码安装”的路线了。

  首先需要设置系统环境变量:VS90COMNTOOLS=%VS100COMNTOOLS%    #其中“VS100COMNTOOLS”是VS2010的编译器,安装VS时貌似自动添加了。

  然后再PIL目录下:>setup.py install   就OK了。

  但是接下来情况发生了:

  

>>>import Image 
>>>img = Image.open("img.jpg")
>>img.rotate(60)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "S:\Python2.7.5\lib\site-packages\PIL\Image.py", line 1359, in rotate
    self.load()
  File "S:\Python2.7.5\lib\site-packages\PIL\ImageFile.py", line 189, in load
    d = Image._getdecoder(self.mode, d, a, self.decoderconfig)
  File "S:\Python2.7.5\lib\site-packages\PIL\Image.py", line 385, in _getdecoder
    raise IOError("decoder %s not available" % decoder_name)
IOError: decoder jpeg not available

  说明JPEG编码不支持,于是我又将图片转换成PNG格式

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "S:\Python2.7.5\lib\site-packages\PIL\Image.py", line 1359, in rotate
    self.load()
  File "S:\Python2.7.5\lib\site-packages\PIL\ImageFile.py", line 189, in load
    d = Image._getdecoder(self.mode, d, a, self.decoderconfig)
  File "S:\Python2.7.5\lib\site-packages\PIL\Image.py", line 385, in _getdecoder
    raise IOError("decoder %s not available" % decoder_name)
IOError: decoder zip not available

   看来还是不支持,但是发现bmp格式的图片支持 img.rotate(); 但是当执行到 img.show() 或 img.save() 时程序就会崩溃。

   查看PIL的 setup.py 文件,可以发现这么一段:

   

# --------------------------------------------------------------------
# Library pointers.
#
# Use None to look for the libraries in well-known library locations.
# Use a string to specify a single directory, for both the library and
# the include files.  Use a tuple to specify separate directories:
# (libpath, includepath).  Examples:
#
# JPEG_ROOT = "/home/libraries/jpeg-6b"
# TIFF_ROOT = "/opt/tiff/lib", "/opt/tiff/include"
#
# If you have "lib" and "include" directories under a common parent,
# you can use the "libinclude" helper:
#
# TIFF_ROOT = libinclude("/opt/tiff")

TCL_ROOT = None
JPEG_ROOT = None
ZLIB_ROOT = None
TIFF_ROOT = None
FREETYPE_ROOT = None
LCMS_ROOT = None

   

   原来是缺少JPEG、ZLib等库的支持。而且在Win下的解决方案就是编译这些库的源码,然后添加到PIL中。


Refer:

http://www.crifan.com/python_install_pip_error_python_version_2_7_required_which_was_not_found_in_the_registry/

http://www.cnblogs.com/byshome/p/3319660.html

   

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值