在Python中运行PIL(Python Imaging Library)的步骤如下:
1. 安装Pillow库:
使用pip安装:
```
pip install Pillow
使用easy_install安装:
```
easy_install Pillow
2. 在Python代码中引入Pillow库:
```python
from PIL import Image
3. 使用Pillow库进行图像处理:
打开图像文件:
```python
im = Image.open('image.jpg')
显示图像:
```python
im.show()
保存图像:
```python
im.save('new_image.jpg')
调整图像尺寸:
```python
new_size = (width, height)
im_resized = im.resize(new_size)
裁剪图像:
```python
box = (left, upper, right, lower)
im_cropped = im.crop(box)
```python
im_gray = im.convert('L')
以上是使用Pillow库进行图像处理的基本操作。Pillow是PIL库的一个分支,提供了更多的功能和更好的兼容性。