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