---
title: "python修改文件尺寸"
author: "莫激动"
date: "2012-08-18T21:35:07Z"
tags: []
categories: ["编程语言"]
slug: "python"
draft: false
lastmod: "2012-08-19T11:50:10Z"
id: 1636775
url: "https://mappings.iteye.com/blog/1636775"
---

python对图片的操作需要使用到(Python Imaging Library)PIL库，PIL可以处理几乎所有的图片类型，了解更多请点击[这里](http://www.pythonware.com/products/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)
```