我在手机上选择一张图片之后进行canvas压缩重新生成图片,然后用canvasToTempFilePath导出图片再上传到后台,可是后台处理不了这个图片,不压缩图片传到后台实在太大了。请问该如何去压缩图片。
var types = e.currentTarget.dataset.zp
var that = this;
wx.chooseImage({
count: 1,
sizeType: [‘compressed’],
success: function(photo) {
wx.getImageInfo({
src: photo.tempFilePaths[0],
success: function(res) {
console.log(res)
var ctx = wx.createCanvasContext(‘attendCanvasId’);
//设置canvas尺寸
ctx.drawImage(photo.tempFilePaths[0], 0, 0, 300, 160)
//将图片填充在canvas上
ctx.draw()
//下载canvas图片
setTimeout(function() {
wx.canvasToTempFilePath({
canvasId: ‘attendCanvasId’,
success: function(res) {
console.log(res.tempFilePath)
if (types == ‘zm’){
that.setData({
zm: res.tempFilePath,
})
}else{
that.setData({
fm: res.tempFilePath,
})
}
}
})
}, 100)
}
})
}
})