【问题标题】:python pillow when I open a portrait (height greater than width) image, the image is rotated ccw 90 degreespython枕头打开纵向(高度大于宽度)图像时,图像逆时针旋转90度
【发布时间】:2021-03-18 07:11:06
【问题描述】:

当我打开一个高于宽度(纵向)的图像时,图像 逆时针旋转 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()

【问题讨论】:

    标签: python image rotation python-imaging-library


    【解决方案1】:

    有几件事。显然 show 将图像保存为 .png 临时文件,并且该保存会丢失 jpg 图像的 exif 数据中的方向信息。我也遇到了旋转问题。枕头图像功能存在一些不一致。例如缩略图更新提供的图像并返回无。 rotate 旋转图像并返回更改后的图像。

    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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-21
      • 1970-01-01
      • 2014-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多