I need to take photos in iPhone and save it in my PC. The images should have the same orientation as when it was taken.
I have my own iPhone app which will take the image and send it as raw data through TCP sockets to the python server running on my PC. The python server receives the image and saves it as JPG in the proper location.
The First Problem
iOS always saves the image as landscape even if we take the photo in portrait mode. The actual orientation is embedded in the EXIF header of the image. Apple devices properly reads the EXIF information and will always display the images properly. But most of the image viewers in Windows doesn't care about the field. So, all images will be displayed as landscape in the PC.
When I receive the image at the python server, I do the following:
- Check the proper orientation by reading the EXIF using pyexvi2.
- Rotate the image to match the actual orientation using wxpython. This will remove the EXIF header.
- Reset the orientation tag in EXIF so that the image will display as-is everywhere.
- Put back the EXIF information into the rotated image.
This actually makes the image display properly. But...
The Second Problem
The thumbnail inside the EXIF is not rotated. As we are doing the EXIF separately, the thumbnail is not processed by anyone.
The Complete Solution
I am taking the thumbnail out of the EXIF, rotating it and putting it back in the EXIF.
Here is the complete code...
Bonus material: Here is how to get the GPS coordinates from an image in Python...
Did this work for you? Comments?