代码上直接没有文字//这是解决exif变化方向的js文件//应用前npminstallexif-js--save或者直接importexif-js////调用方法//让baseData;//imgExif(file,function(base){//baseData=base//});importExiffrom'exif-js'//引入exifletu={};//转换的主要方法u.index=(file,callback)=>{letOrientation,resultData;//图片的方向,返回值//获取拍照时的信息,解决图片旋转的问题Exif.getData(file,function(){Orientation=Exif.getTag(this,'方向');});//检查是否支持FileReaderif(!file||!window.FileReader)return;//检查是否支持FileReaderif(!file||!window.FileReader)return;if(/^image/.test(file.type)){//创建一个阅读器letreader=newFileReader();//将图像2转换为base64格式reader.readAsDataURL(file);//读取成功回调reader.onloadend=function(){letresult=this.result;//判断图片是否有方向值,不直接返回base64if(!Orientation){callback(result);}else{letimg=newImage();img.src=结果;//图片信息加载及转换方向img.onload=function(){resultData=u.compress(img,方向);回调(结果数据);}}}}};//改变旋转方向u.compress=(img,Orientation)=>{letcanvas=document.createElement("canvas"),ctx=canvas.getContext('2d'),tCanvas=document.createElement("canvas"),tctx=tCanvas.getContext("2d"),initSize=img.src.length,width=img.width,height=img.height,ratio=1;//声明canvas.width=width;canvas.height=高度;//设置背景色ctx.fillStyle="#fff";ctx.fillRect(0,0,canvas.width,canvas.height);//如果图片像素大于100万,则使用tile绘制letcount;if((count=width*height/1000000)>1){//console.log("超过100W像素");count=~~(Math.sqrt(count)+1);//计算要分成多少块//计算每个块的宽和高letnw=~~(width/count);让nh=~~(高度/计数);tCanvas.width=nw;tCanvas.height=nh;for(leti=0;i
