Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImageProcessor EXIF Orientation tag #3

Open
lehins opened this issue Jan 21, 2015 · 1 comment
Open

ImageProcessor EXIF Orientation tag #3

lehins opened this issue Jan 21, 2015 · 1 comment
Assignees

Comments

@lehins
Copy link
Owner

lehins commented Jan 21, 2015

Need to implement automatic orientation adjustment whenever Orientation EXIF tag is present on JPEG and TIFF formats.

@lehins lehins self-assigned this Jan 30, 2015
@dmytrofrolov
Copy link

Apparently PIL library behaves wrong with images that has EXIF tags.
Details:
Rotating an image with orientation specified in EXIF using Python without PIL including the thumbnail

Possible workaround:
PIL Library introduced PIL.ImageOps.exif_transpose(image)->Image method that deals with it properly.
The least invasive workaround is to add such method call somewhere in ImageProcessor:

from PIL import ImageOps

class CustomImageProcessor(ImageProcessor):
    def get_image(self, stream, **kwargs):
        image = super(CustomImageProcessor, self).get_image(stream, **kwargs)
        return ImageOps.exif_transpose(image)

and then, use CustomImageProcessor class in Model

class ProductImage(Base):
    product = models.ForeignKey(
        "product.Product",
        on_delete=models.CASCADE,
    )
    file = fields.ImageField(
        _("Image"),
        upload_to="product",
        dependencies=[
            FileDependency(
                attname="file_original",
                processor=CustomImageProcessor(
                    format="JPEG", scale={"max_width": 1024, "max_height": 768}
                ),
            ),
        ],
    )
    file_original = fields.ImageField(
        _("Image original"), upload_to="original", blank=True, null=True
    )

This workaround works for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants