-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Open
Description
What's the problem?
/view endpoint returns image with wrong orientation when:
- The image has
EXIF orientationAND previewparameter is passed ORchannelparameter is not "rgba"
Why does it happen?
# server.py / view_image()
# modified a little bit for better understanding
...
if 'preview' in request.rel_url.query:
with Image.open(file) as img:
... # do some image processing
return web.Response(body=buffer.read(), content_type='image/png',
headers={"Content-Disposition": f"filename=\"{filename}\""})
elif channel == 'rgb':
with Image.open(file) as img:
... # do some image processing
return web.Response(body=buffer.read(), content_type='image/png',
headers={"Content-Disposition": f"filename=\"{filename}\""})
elif channel == 'a':
with Image.open(file) as img:
... # same here
return web.Response(body=alpha_buffer.read(), content_type='image/png',
headers={"Content-Disposition": f"filename=\"{filename}\""})
else:
return web.FileResponse(file, headers={"Content-Disposition": f"filename=\"{filename}\""})As you see, view_image() returns the original file with EXIF info in else condtion, and therefore the orientation in this case is correct.
However, in other cases, it opens the image, performs some image processing, and then returns the modified image without EXIF information. Therefore the resulting image will have wrong orientation if the image has EXIF orientation not equal to 1.
(Refer to this for more information about EXIF orientation)
How can we fix it?
Adding the below one line will solve the problem:
# right after opening the image
img = ImageOps.exif_transpose(img) # this corrects the image orientation according to the EXIF infoMetadata
Metadata
Assignees
Labels
No labels
