Question

I am building an application in HTML5 for iPad to upload a picture to a server. When I click an input file element like this:

<input id='fileup' type='file' accept='image/*' name='upf' onchange='abv();'/>

It gives the possibility to either take a picture from the device camera or to upload from existing ones. However, when taking a picture, the resulting image is rotated based on the orientation of the device at the moment the photo is taken. What I want to do is to figure out the orientation of the captured image and try to rotate it on the server-side.

Notice that I do not have access to any iOS tools or frameworks, since this application is totally web-based.

Then, is there any information regarding the orientation of the picture that I can either access on the client or on the server-side, such that I would be able to rotate the images into the proper position? I have heard of EXIF data, but I am unsure on how to access it, and if it would give me the required information.

I am using python on the server-side, but a solution in C/C++ would also be appreciated.

Thanks.

Was it helpful?

Solution

I am using python on the server-side

So you can use jpegtran-cffi Python package that provides the ability to perform EXIF auto-transform:

# jpegtran can transform the image automatically according to the EXIF
# orientation tag
photo = JPEGImage(blob=requests.get("http://example.com/photo.jpg").content)
print photo.exif_orientation  # "6" (= 270°)
print photo.width, photo.height # "4320 3240"
corrected = photo.exif_autotransform()
print corrected.exif_orientation  # "1" (= "normal")
print corrected.width, corrected.height  # "3240 4320"

Note: extracted from the README.


As an alternative there is also a convenient command-line tool called jhead that you can use for the same purpose:

#    Remove EXIF orientation
#    i.e. rotate the image accordingly and reset the orientation
#    flag to 1 (default, i.e. origin = TopLeft)
#    WARNING: the image file is overwritten!
#    NOTE: it also works with a wildcard: jhead -autorot *.jpg
jhead -autorot myimage.jpg
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top