mirror of
https://gitee.com/java110/PropertyApp.git
synced 2026-02-23 21:36:39 +08:00
优化代码
This commit is contained in:
parent
b44e2b509e
commit
bccd2d1dcb
@ -79,17 +79,29 @@ function imageToBease64(that, imageUrl, callback) {
|
||||
const canvas = res[0].node;
|
||||
const ctx = canvas.getContext('2d');
|
||||
const image = canvas.createImage();
|
||||
canvas.width = imgData.width;
|
||||
canvas.height = imgData.height;
|
||||
|
||||
image.src = imgData.path;
|
||||
image.onload = function() {
|
||||
const canvasWidth = imgData.width; // 获取图片宽度
|
||||
const canvasHeight = imgData.height; // 获取图片高度
|
||||
ctx.drawImage(image, 0, 0, canvasWidth, canvasHeight); // 绘制图片
|
||||
let h = imgData.height;
|
||||
// 默认按比例压缩
|
||||
let w = imgData.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);
|
||||
}
|
||||
}
|
||||
canvas.width = w;
|
||||
canvas.height = h;
|
||||
ctx.drawImage(image, 0, 0, w, h); // 绘制图片
|
||||
|
||||
// 设置水印样式
|
||||
addWaterMark(ctx, imgData.width, imgData.height);
|
||||
addWaterMark(ctx, w, h);
|
||||
|
||||
//压缩比例
|
||||
let quality = 0.3;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user