Fre*_*ore 0 python image python-imaging-library
我正在尝试使用 PIL 在 python 中旋转图像,但是当使用 PIL 旋转时,它会保留图像的原始尺寸。例如,如果我尝试旋转它,它的边缘就会被切断。解释这一点的最简单方法是向您展示:
有没有一种方法可以旋转图像,然后保存旋转后的版本,而无需使用 PIL 进行裁剪?或者,如果使用 PIL 无法做到这一点,您会推荐哪些其他方法。
小智 5
我不确定您正在使用的代码段是什么,但我猜您没有使用expand=True实际rotate()扩展图像以适应旋转图像的函数。请在官方 Pillow 文档中查找信息。
下面是实际的代码,可供参考。
from PIL import Image
# open image
image=Image.open('sample.jpg')
# rotate image
image=image.rotate(90, expand=True)
# save image
image.save('newsample.jpg')
Run Code Online (Sandbox Code Playgroud)