从图像中剥离EXIF数据

时间:2014-12-24 14:27:45

标签: javascript exif

如何通过javascript从上传的图片中删除EXIF数据?我目前能够使用this exif-js plugin访问EXIF数据,如下所示:

EXIF.getData(oimg, function() {
    var orientation = EXIF.getTag(this, "Orientation");
});

但是,我还没有找到任何方法来实际删除Exif数据,只是为了检索它。

更具体地说,我正在努力摆脱在某些浏览器上旋转我的图像的方向Exif数据。

1 个答案:

答案 0 :(得分:19)


以下是它的一个小演示,选择带有方向数据的图像,以查看它的外观和外观(仅限现代浏览器)。

http://jsfiddle.net/mowglisanu/frhwm2xe/3/

<input id="erd" type="file"/>
var input = document.querySelector('#erd');
input.addEventListener('change', load);
function load(){
    var fr = new FileReader();
    fr.onload = process;
    fr.readAsArrayBuffer(this.files[0]);
    window.open(URL.createObjectURL(this.files[0]), "_blank", "toolbar=yes, scrollbars=yes, resizable=yes, top=500, left=500, width=400, height=400");
}
function process(){
    var dv = new DataView(this.result);
    var offset = 0, recess = 0;
    var pieces = [];
    var i = 0;
    if (dv.getUint16(offset) == 0xffd8){
        offset += 2;
        var app1 = dv.getUint16(offset);
        offset += 2;
        while (offset < dv.byteLength){
            console.log(offset, '0x'+app1.toString(16), recess);
            if (app1 == 0xffe1){

                pieces[i] = {recess:recess,offset:offset-2};
                recess = offset + dv.getUint16(offset);
                i++;
            }
            else if (app1 == 0xffda){
                break;
            }
            offset += dv.getUint16(offset);
            var app1 = dv.getUint16(offset);
            offset += 2;
        }
        if (pieces.length > 0){
            var newPieces = [];
            pieces.forEach(function(v){
                newPieces.push(this.result.slice(v.recess, v.offset));
            }, this);
            newPieces.push(this.result.slice(recess));
            var br = new Blob(newPieces, {type: 'image/jpeg'});
            window.open(URL.createObjectURL(br), "_blank", "toolbar=yes, scrollbars=yes, resizable=yes, top=500, left=500, width=400, height=400");
        }
    }       
}