exif
可交换图像文件格式(英语:Exchangeable image file format,官方简称Exif),是专门为数码相机的照片设定的文件格式,可以记录数码照片的属性信息和拍摄数据。Exif可以附加于JPEG、TIFF、RIFF等文件之中,为其增加有关数码相机拍摄信息的内容和索引图或图像处理软件的版本信息。
现在人们对隐私越来越注重,所以我们作为开发者来说,用户上传照片,为了不暴露用户信息,有必要将这些信息在上传的时候抹除掉,保证用户隐私安全。
通过exif-js获取图片信息
// 先安装依赖,也可以直接引入js文件
<script src="https://cdn.jsdelivr.net/npm/exif-js"></script>
<script>
btn.addEventListener('click', function () {
let img = document.getElementById("img");
EXIF.getData(img, function () {
let make = EXIF.getTag(this, "Make");
let model = EXIF.getAllTags(this);
console.log(JSON.stringify(model));
});
});
</script>
<img src="imgUrl" style="height: 300px;" id="img" />
<button id="btn">获取exif</button>
拿到exif数据就可以获取到拍照的设备型号及地理位置等信息。具体字段说明参考exif字段
删除图片exif数据
目前想到的办法就是拿到图片的数据,然后利用canvas重新绘制。如果有更好的办法可以相互交流。
let imgEl = new Image();
imgEl.src = "imgURL"; // 文件url,blob,base64都可以
imgEl.onload = function () {
let canvas = document.createElement('canvas');
let ctx = canvas.getContext('2d');
canvas.width = imgEl.width;
canvas.height = imgEl.height;
ctx.drawImage(imgEl, 0, 0, imgEl.width, imgEl.height);
// 处理去除exif数据后的图像,进行自己的逻辑
}
查看exif数据也可以通过下面的网站: exif.tools/ 或者是下载exiftool
安卓手机发送图片文件到mac比较好用的软件:openmtp.ganeshrvel.com/
其它方式参考:www.kkgcn.com/9007.html (没有尝试)