pillow

Pillow中怎么旋转图像

小亿
151
2024-05-22 17:06:10
栏目: 编程语言

在Pillow中旋转图像可以使用rotate()方法。

示例代码:

from PIL import Image

# 打开图像文件
image = Image.open('example.jpg')

# 旋转图像,顺时针旋转90度
rotated_image = image.rotate(90)

# 保存旋转后的图像
rotated_image.save('rotated_example.jpg')

# 显示旋转后的图像
rotated_image.show()

在上面的示例中,我们首先打开一个图像文件,然后使用rotate()方法来旋转图像,可以指定旋转的角度。最后保存旋转后的图像并显示出来。

0
看了该问题的人还看了