1

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.

4

1 回答 1

1

我在服务器端使用 python

所以你可以使用jpegtran-cffi Python 包,它提供了执行 EXIF自动转换的能力:

# 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"

注意:摘自自述文件。


作为替代方案,还有一个名为jhead的便捷命令行工具,您可以将其用于相同目的:

#    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
于 2014-03-21T08:33:56.467 回答