python pil image
时间: 2023-08-25 14:05:45 浏览: 188
PIL (Python Imaging Library)是一个Python图像处理库,用于创建、打开、编辑和保存多种图像格式。
以下是使用PIL库加载、编辑和保存图像的示例代码:
```python
# 导入PIL库
from PIL import Image
# 打开一张图片
image = Image.open("example.jpg")
# 显示图片
image.show()
# 调整图片大小
new_size = (500, 500)
resized_image = image.resize(new_size)
# 旋转图片
angle = 45
rotated_image = image.rotate(angle)
# 保存图片
resized_image.save("resized_example.jpg")
rotated_image.save("rotated_example.jpg")
```
在这个示例中,我们使用PIL库打开了一张名为“example.jpg”的图片,显示了它,并调整了它的大小和旋转角度,最后将调整后的图片保存为新文件。
相关问题
python PIL包Image类
Python的PIL包是Python图像处理库,其中的Image类是PIL包中最重要和最常用的类之一。它提供了许多常用的图像处理方法,例如打开、保存、缩放、裁剪、旋转、滤镜等等。使用Image类可以轻松地处理各种图像格式,包括JPEG、PNG、GIF等等。例如,以下代码演示了如何使用Image类打开一张图片,并将其转换为黑白模式:
```python
from PIL import Image
# 打开图片
image = Image.open('test.jpg')
# 转换为黑白模式
bw_image = image.convert('L')
# 显示图片
bw_image.show()
```
这段代码首先使用Image类打开了一张名为test.jpg的图片,然后使用convert方法将其转换为黑白模式,最后使用show方法显示出来。
python PIL.Image.open()
PIL是Python Imaging Library的缩写,是Python中一个强大的图像处理库。PIL中的Image模块提供了一个类,可以用来打开、操作和保存不同格式的图像文件。其中,PIL.Image.open()函数可以打开一个图像文件,并返回一个Image对象,可以对该对象进行各种操作,例如调整大小、旋转、裁剪等。
阅读全文
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![application/x-gzip](https://img-home.csdnimg.cn/images/20250102104920.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)