Move some functions to Util, Bug Fixes, new stuff

This commit is contained in:
Dragon Fire
2020-03-13 22:59:22 -04:00
parent bf7579c4ac
commit 0edac3e86d
14 changed files with 99 additions and 92 deletions
+20
View File
@@ -126,4 +126,24 @@ module.exports = class CanvasUtil {
return resolve(lines);
});
}
static centerImage(base, data) {
const dataRatio = data.width / data.height;
const baseRatio = base.width / base.height;
let { width, height } = data;
let x = 0;
let y = 0;
if (baseRatio < dataRatio) {
height = data.height;
width = base.width * (height / base.height);
x = (data.width - width) / 2;
y = 0;
} else if (baseRatio > dataRatio) {
width = data.width;
height = base.height * (width / base.width);
x = 0;
y = (data.height - height) / 2;
}
return { x, y, width, height };
}
};