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

Image.open transposing the image automatically on open? #1188

Closed
ferozed opened this issue Apr 13, 2015 · 6 comments
Closed

Image.open transposing the image automatically on open? #1188

ferozed opened this issue Apr 13, 2015 · 6 comments
Labels
Bug Any unexpected behavior, until confirmed feature.
Milestone

Comments

@ferozed
Copy link

ferozed commented Apr 13, 2015

I have an image that I took using Iphone in portrait mode. When the iphone stores this image, it stores an Exif Orientation tag with value 6 on the image. This means that the image needs to be rotate left 90deg to get back the original.

Now, I do the following:

i = Image.open('image.jpg')
i.show()

expecting to see the original image rotated 90, i.e the way the iphone saved it. but instead I am getting a corrected image.

If I save the image as a different file, and look at it using "eog" which is the image viewer on my ubuntu box, I again get the "corrected" image. If I use "eog" to look at the original image, I see an image rotated 90deg ( as I expect ).

why is Image.open () rotating the image ?

My use case, is that I have an image processing application, and I need to correct the source image orientation depending on the exif tag.

@radarhere
Copy link
Member

While I can see the question you're asking is - why doesn't Pillow automatically rotate the image? - I feel like you're also raising the question - when you open and save an image, should the result be the same as the original, rather than the EXIF data being lost?

@radarhere
Copy link
Member

Also, if you're interested in just solving the problem within your own code, http://stackoverflow.com/questions/4228530/pil-thumbnail-is-rotating-my-image/ should have what you're looking for.

@ferozed
Copy link
Author

ferozed commented Apr 14, 2015

hi! Thanks for your quick response. I should have worded my question better.

My use case is as follows:

I have an image processing system which processes photos and renders them into sizes for display. The photos could be taken by various devices like cameras etc. When the photo is taken by an iphone in portrait mode, then the photo is marked with the exif rotation tag. We want to process this tag, and rotate the photo to get it back into it's proper orientation before creating the sizes.

The SO article you pointed to, that is exactly what we are doing. We read the EXIF tag from the image, and then apply transformation on the image to get it back to it's correct orientation before doing further processing.

Now, onto our problems:

  1. The transform doesnt seem to work. In that, doing an im.show() on the before and after image shows the same image.

  2. that is because, doing an im.show() on the original image is showing the corrected image, not the original image. I dont know if this correction is being done by the show() method of the Image class, or by the imagemagick based viewer, or what??

@homm
Copy link
Member

homm commented Apr 22, 2015

The transform doesnt seem to work. In that, doing an im.show() on the before and after image shows the same image.

So you have a error somewhere in your code, not in Pillow, right? If you want, you can show the code and someone can help you.

Feroze, let's understand the terminology. As I know, Pillow does not rotate any images. It shows and saves exactly the pixels stored in the original image. You see rotated image not because Pillow rotate it. This is because the image is really stored rotated. Other software (not all, by the way) can show the image in correct orientation if it analyzes a meta information (EXIF). You can keep or discard a meta information while saving back in JPEG. You can manually rotate actual image data and discard rotation information while saving or displaying. You can't keep a meta information while displaying, because display() saves an image in BMP format, which doesn't allow this information.

@ferozed
Copy link
Author

ferozed commented Apr 27, 2015

hi! Thanks for your response. The problem turned out to be bad image metadata in the image. The image was upright, but it's metadata said RightTop (Orientation = 6). So, when I did a Image.open('image.jpg').show() it showed the upright image, and I thought that either PIL, or the show() operation was autocorrecting the image rotation. Turned out not to be the case.

But I did notice one issue. I have a collection of images that have this problem. PIL is correctly reporting the orientation of those images. However, when I run jpegexiforient tool from jpeg-tools, it doesnt give me any orientation info. Is JPEG reading the orientation from a different place?

OTOH if I take an image with my IPhone with different orientations, the jpegexiforient and PIL/Pillow show the correct value for Orientation EXIF tag.

For your help, I have put the images that are showing inconsistent behavior in s3:

$ s3t ls s3://feroze/exif/
2015-04-16 18:28 3266 s3://feroze/exif/1.jpg
2015-04-16 18:28 11987 s3://feroze/exif/2.jpg
2015-04-16 18:28 7004 s3://feroze/exif/3.jpg
2015-04-16 18:28 15437 s3://feroze/exif/4.jpg
2015-04-16 18:28 13042 s3://feroze/exif/5.jpg
2015-04-16 18:28 3874 s3://feroze/exif/6.jpg
2015-04-16 18:28 15058 s3://feroze/exif/7.jpg
2015-04-16 18:28 5990 s3://feroze/exif/8.jpg
2015-04-16 18:28 139435 s3://feroze/exif/L1.jpg
2015-04-16 18:28 140588 s3://feroze/exif/L4.jpg
2015-04-16 18:28 645011 s3://feroze/exif/image.jpg

You can download these using:

curl -s http://feroze.s3.amazonaws.com/1.jpg

etc.

THe 1.jpg through 6.jpg are images that have orientation set to 1 through 6.

These images have the correct orientation set.

image.jpg is an upright image, but has orientation set to 6. This is the one that had me confused.

@aclark4life aclark4life added the Bug Any unexpected behavior, until confirmed feature. label Jun 28, 2015
@aclark4life aclark4life added this to the Future milestone Jun 28, 2015
@radarhere
Copy link
Member

Rereading the last post in this, you seem to be saying that Pillow is actually exhibiting the correct behaviour, and that there isn't a problem?

Also, the images that you linked to are no longer accessible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Any unexpected behavior, until confirmed feature.
Projects
None yet
Development

No branches or pull requests

5 participants