문제

Note: I am not looking to modify the EXIF data!

I'm trying to re-orient an image based on its EXIF data. If the Orientation value is 3, 6, or 8, I rotate it accordingly.

The problem I have, now, is that after the rotate() I get back an image with no format, as the docs say.

im.format ⇒ string or None

The file format of the source file. For images created by the library itself (via a factory function, or by running a method on an existing image), this attribute is set to None.

So therefore I can't call _getexif() on the image returned by rotate(), since it's not a member of the returned class. How can I verify programmatically that the rotation was correct?

Edit: I did notice that there is an 'exif' key in the image's .info dict but it's a byte string, so I don't know what to do with it.

도움이 되었습니까?

해결책

For 90-degree (clockwise and anti-clockwise) rotations you can verify the width and height values have switched. Obviously this won't help for square images (unlikely for photos).

For 180-degree rotations, verify the width and height haven't changed. Further, you could take some measure of some top rows and bottom rows. For example, convert to greyscale and count the darkness (or keep as colour and count the blueness). Allowing for some variation, the darker side should now be on the other side. You could also measure some left and right rows. Similarly this could be applied for 90-degree rotations.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top