在Python中运行PIL(Python Imaging Library)的步骤如下:
1. 安装Pillow库:
使用pip安装:
pip install Pillow
使用easy_install安装:
easy_install Pillow
2. 在Python代码中引入Pillow库:
from PIL import Image
3. 使用Pillow库进行图像处理:
打开图像文件:
im = Image.open('image.jpg')
显示图像:
im.show()
保存图像:
im.save('new_image.jpg')
调整图像尺寸:
new_size = (width, height)
im_resized = im.resize(new_size)
裁剪图像:
box = (left, upper, right, lower)
im_cropped = im.crop(box)
im_gray = im.convert('L')