温馨提示×

Pillow中怎么旋转图像

小亿
215
2024-05-22 17:06:10
栏目: 编程语言
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

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

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读:Pillow中如何实现图像的频域滤波

0