图片压缩时 不能大于1080

This commit is contained in:
java110 2021-05-30 09:37:31 +08:00
parent 75362a6342
commit 277e96f0f7

View File

@ -21,9 +21,21 @@ export function translate(imgSrc, callback) {
var h = that.height;
// 默认按比例压缩
var w = that.width;
if(h > 1080 || w > 1080){
let _rate = 0;
if(h > w){
_rate = h/1080;
h = 1080;
w = Math.floor(w/_rate);
}else{
_rate = w/1080;
w = 1080;
h = Math.floor(h/_rate);
}
}
var canvas = document.createElement('canvas');
var ctx = canvas.getContext('2d');