PIL 的 Image.rotate 给我 90 度而不是 270 度

问题描述 投票:0回答:1

Python 3.11.8 皮尔 10.2.0

我正在尝试将此图像旋转 270 度:

我的代码:

from PIL import Image

image = Image.open("test.jpg")
image = image.rotate(270, expand=True)
image.save("test_out.jpg")

但是结果是:

对我来说是 90 度旋转

我怀疑自动方向和 exif 数据弄乱了我,所以我在旋转之前分别尝试了这些命令,但它们也无助于获得预期的结果:

image = ImageOps.exif_transpose(image)
image.getexif().clear()

当我使用其他工具时:

convert test.jpg -rotate 270 test_out.jpg

我得到了预期的结果:

python image-processing python-imaging-library
1个回答
0
投票
# To switch rotation i.e. clockwise or counterclockwise 
# Use negative value
image = image.rotate(-270, expand=True)
image

输出:

© www.soinside.com 2019 - 2024. All rights reserved.