简体   繁体   English

来自iOS相机的图像在Web应用程序中旋转发送

[英]Images from iOS camera are sent rotated in web application

I am building an application in HTML5 for iPad to upload a picture to a server. 我正在HTML5中为iPad构建应用程序,以将图片上传到服务器。 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. 请注意,由于此应用程序完全基于Web,因此我无权访问任何iOS工具或框架。

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. 我听说过EXIF数据,但是不确定如何访问它,以及它是否可以提供所需的信息。

I am using python on the server-side, but a solution in C/C++ would also be appreciated. 我在服务器端使用python,但也希望使用C / C ++解决方案。

Thanks. 谢谢。

I am using python on the server-side 我在服务器端使用python

So you can use jpegtran-cffi Python package that provides the ability to perform EXIF auto-transform : 因此,您可以使用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"

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: 另外,还有一个方便的命令行工具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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM