Detect whether the loading image is taken from camera directly, when using smartphones

旧时模样 提交于 2019-12-01 12:01:33

I have found the solution by myself, so I want to participate it:

What I needed is translate the binary data to exif data, so on exif.js, I added the following.

jQuery.fn.getExif = function() {
    var exif;
    var bin;
    var bf;
    bin = atob(this.attr("src").split(',')[1]);
    if (bin) {
        bf = new BinaryFile(bin);
    }
    if (bf) {
        exif = EXIF.readFromBinaryFile(bf);
    }
    if (exif) {
        this.attr("exifdata", exif);
    }
    return exif;
}

and use the above on code - just get any exif value I want.

The main issue is that the image should be rotated according to exif (if, i.e. the orientation is 90 degrees clockwise, so I should rotate 90 counterclockwise, in order to fix the orientation) - No problem on most devices, but there is a problem that persists on several devices, such as IPAD.

IPAD (or Safari - I don't know exactly where might be the problem) do me a favour, and auto rotate the image, when I am loading it from file, so it is displayed always correctly.

Now how can I know when to rotate the image and when not rotating it.

Thanks :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!