ITeye博客

python修改文件尺寸

莫激动 · 2012-08-18 21:35 · python · 编程语言 · Markdown

python对图片的操作需要使用到(Python Imaging Library)PIL库,PIL可以处理几乎所有的图片类型,了解更多请点击这里(可能被墙请自带梯子)。

1.下载PIL并安装

    windows:直接下载对应的安装包

    linux:

yum install python-imaging
或
sudo apt-get install python-imaging
或
直接通过源码安装

 

2.使用

 

import Image
img = Image.open('example.jpg')
new_img= img.resize((w, h),Image.ANTIALIAS) # w代表宽度,h代表高度,最后一个参数指定采用的算法
nwe_img.save('example-new.jpg',quality=100)

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。