Windows下安装PIL进行图像处理

过程一波三折

参考

http://blog.csdn.net/zxia1/article/details/8254113

http://stackoverflow.com/questions/3544155/about-the-pil-error-ioerror-decoder-zip-not-available

 

解决方法:

http://www.lfd.uci.edu/~gohlke/pythonlibs/下载pillow,安装

 

然后创建如下代码测试

   1: import os,sys
   2: from PIL import Image  
   3:  
   4: pic = Image.open("test.png")
   5: pic.show()

pip是一个很好的工具,类似apt,可以为python管理模块

 

PIL相关的参考手册:

http://effbot.org/imagingbook/

 

缩小图片操作

   1: import os,sys
   2: from PIL import Image
   3:  
   4:  
   5: MAX_WIDTH = 2048
   6: MAX_HEIGHT = 1536
   7:  
   8:  
   9: pic = Image.open("test1.jpg")
  10: width,height = pic.size
  11:  
  12:  
  13: small = pic.resize((width / 2,height / 2))
  14: ##small.show()
  15: small.save("test1_small.jpg")
posted @ 2013-12-27 13:54  Daniel King  阅读(985)  评论(0编辑  收藏  举报