Javascript 从图像中提取 exif 方向数据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14270574/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 16:13:56  来源:igfitidea点击:

extract exif orientation data from image

javascripthtmljpegexif

提问by jujule

Possible Duplicate:
Accessing JPEG EXIF rotation data in Javascript on the client side

可能的重复:
在客户端访问 Javascript 中的 JPEG EXIF 旋转数据

I'd need to extract the orientation EXIF data from an HTML JPEG image with Javascript.

我需要使用 Javascript 从 HTML JPEG 图像中提取方向 EXIF 数据。

according to exiftool's documentationthe orientation flag is found at offset 0x112 within the EXIF marker, and occupies 2 bytes.

根据exiftool 的文档,方向标志位于 EXIF 标记内的偏移量 0x112 处,占用 2 个字节。

I guess we just need to extract the data at good offset and 'convert' the value but i don't have any idea how to achieve this in the browser. The result value should be a number between 1 and 8 describing the orientation.

我想我们只需要以良好的偏移量提取数据并“转换”该值,但我不知道如何在浏览器中实现这一点。结果值应该是 1 到 8 之间的数字,用于描述方向。

How to read that data from a simple IMG tag ? I need a webkit only solution, but browser only.

如何从简单的 IMG 标签中读取数据?我只需要一个 webkit 解决方案,但只需要浏览器。

Thanks !

谢谢 !

采纳答案by Colin Pear

Possible duplicate of this question.

这个问题的可能重复。

thanks. here's the final code example to get orientation :

谢谢。这是获得方向的最终代码示例:

var b64 = "data:image/jpeg;base64,/9j/4AAQSkZJRgABA......";
var bin = atob(b64.split(',')[1]);
var exif = EXIF.readFromBinaryFile(new BinaryFile(bin));
alert(exif.Orientation);