扫描二维码下载沐宇APP

沐宇

微信扫码使用沐宇小程序

沐宇

Pillow中怎么旋转图像

扬州沐宇科技
2024-05-22 17:06:10
pillow

在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()方法来旋转图像,可以指定旋转的角度。最后保存旋转后的图像并显示出来。

扫码添加客服微信