总体思路调取getImageInfo获取图片orientation参数,通过orientation返回值调用canvas重新生成图片。
getImgInfo(e,src){
const that = this;
wx.getImageInfo({
src: src,//图片的路径,支持网络路径、本地路径、代码包路径
success:(res)=>{
let canvasContext = wx.createCanvasContext('canvas')
//获得exif中的orientation信息
if(res.orientation == "right"){
var width = res.width;
var height = res.height;
this.setData({
imageWidth: width,
imageHeight: height,
})
canvasContext.translate(width / 2, height / 2)
canvasContext.rotate(90 * Math.PI / 180)
canvasContext.drawImage(src, -width / 2, -height / 2, width, height);
that.setData({
publicSrc:src
})
canvasContext.draw(false,()=>{
wx.canvasToTempFilePath({
x: 0,
y: 0,
canvasId: 'canvas',
success(res) {
let shareImg = res.tempFilePath;
//上传图片方法
//todo
},
fail: function (res) {
}
})
})
}else{
//上传图片方法
//todo
}
}
})
},