python pillow 当我打开人像(高度大于宽度)图片时,图片逆时针旋转90度
python pillow when I open a portrait (height greater than width) image, the image is rotated ccw 90 degrees
当我打开一个高于宽度(纵向)的图像时,图像
逆时针旋转 90 度。
from PIL import ImageTk, Image
from pathlib import Path
wd = Path.cwd()
fn = wd / 'sample.jpg'
path = str(fn)
img = Image.open(path)
img.show()
几件事。显然 show 将图像保存为 .png 临时文件,并且该保存会丢失 jpg 图像的 exif 数据中的方向信息。我在旋转方面也遇到了麻烦。枕头图像功能存在一些不一致。例如thumbnail 更新提供的图像和 return None。
rotate 旋转图像并 return 更改图像。
fimage.thumbnail((700,700), Image.ANTIALIAS)
simage = fimage.rotate(270)
# update. Transpose will use EXIF data if available to
# rotate the image to the correct orientation
from PIL import ImageOps
img = ImageOps.exif_transpose(img)
参考:https://pillow.readthedocs.io/en/stable/reference/ImageOps.html#PIL.ImageOps.exif_transpose
当我打开一个高于宽度(纵向)的图像时,图像 逆时针旋转 90 度。
from PIL import ImageTk, Image
from pathlib import Path
wd = Path.cwd()
fn = wd / 'sample.jpg'
path = str(fn)
img = Image.open(path)
img.show()
几件事。显然 show 将图像保存为 .png 临时文件,并且该保存会丢失 jpg 图像的 exif 数据中的方向信息。我在旋转方面也遇到了麻烦。枕头图像功能存在一些不一致。例如thumbnail 更新提供的图像和 return None。 rotate 旋转图像并 return 更改图像。
fimage.thumbnail((700,700), Image.ANTIALIAS)
simage = fimage.rotate(270)
# update. Transpose will use EXIF data if available to
# rotate the image to the correct orientation
from PIL import ImageOps
img = ImageOps.exif_transpose(img)
参考:https://pillow.readthedocs.io/en/stable/reference/ImageOps.html#PIL.ImageOps.exif_transpose