Skip to content

Add a switch to control whether image.copy() or not in ImageOps.exif_transpose #7086

@yantaozhao

Description

@yantaozhao

What did you expect to happen?

  • Python: 3.9+
  • Pillow: 9.5

Add a switch flag to control whether image.copy() or not if no orientation or orientation=1 in exif to the experimental function ImageOps.exif_transpose.

As pointed out in #5574 (comment) , pillow wants to keeps the output consistent .
However there's unnecessary computation&time cost, and even in many cases where the copy() is not needed, for example:

# Just open image with correct look as human eyes'

from PIL import Image
im = Image.open("hopper.jpg")
im = ImageOps.exif_transpose(im)  #assign to the same variable

#or simplified by:
im = ImageOps.exif_transpose(Image.open("hopper.jpg"))

It's better to let the user decide explicitly when he/she knows what's happening under the hood and wants more control. For lazy user just keep the old consistent manner.

the code maybe like this or something similar:

# Defined in ImageOps.py
def exif_transpose(image, copy_when_no_transpose=True):
    # check orientation in exif
    if method is not None:
        # do something
        return transposed_image
    else:
        return image.copy() if copy_when_no_transpose else image


----------------------------------------

# Called in user code
im = exif_transpose(im, copy_when_no_transpose=False)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions