export const DeleteExif = (file) => {
var fr = new FileReader();
fr.onload = function () {
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) {
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" });
// br就是处理完成之后的结果,这里在处理完成之后我进行了下载
const link = document.createElement("a");
const evt = document.createEvent("MouseEvents");
link.style.display = "none";
link.href = window.URL.createObjectURL(br);
link.download = "me";
document.body.appendChild(link);
// 此写法兼容可火狐浏览器
evt.initEvent("click", false, false);
link.dispatchEvent(evt);
document.body.removeChild(link);
}
}
};
fr.readAsArrayBuffer(file);
};