Strip EXIF data from image

后端 未结 1 690
梦如初夏
梦如初夏 2021-02-04 04:12

How can I strip the EXIF data from an uploaded image through javascript? I am currently able to access the EXIF data using this exif-js plugin, like this:

EXIF.g         


        
相关标签:
1条回答
  • 2021-02-04 04:49
    • look up the file format and exif format
    • read the file into arraybuffer
    • find the required data and remove it
    • create a blob from the remaining data
    • upload it with ajax

    Here is a little demo of it, select an image with orientation data to see how it looks with and with out it(modern browsers only).

    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");
            }
        }       
    }
    
    0 讨论(0)
提交回复
热议问题