如何通过
JavaScript从上传的图像中剥离EXIF数据?我目前可以使用
this exif-js plugin访问EXIF数据,像这样:
EXIF.getData(oimg,function() { var orientation = EXIF.getTag(this,"Orientation"); });
但是,我没有找到任何方法来实际删除Exif数据,只能检索它.
更具体地说,我正在努力去摆脱在某些浏览器上旋转图像的Exif数据.
解决方法
>查看
file format和
exif format
> read the file进 arraybuffer
> find所需数据和 remove it
>从剩余的数据创建一个 blob
> upload它与 ajax
> read the file进 arraybuffer
> find所需数据和 remove it
>从剩余的数据创建一个 blob
> upload它与 ajax
这是一个小的演示,选择一个图像与方向数据,看看它的外观与它(仅现代浏览器).
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),height=400"); } } }