您的位置:宽带测速网 > 编程知识 > Pillow中怎么旋转图像

Pillow中怎么旋转图像

2025-06-27 16:47来源:互联网 [ ]

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