Test allowing any image to be used in meme commands

This commit is contained in:
Dragon Fire
2020-03-22 23:32:07 -04:00
parent 16a14f2472
commit 7239ff6d91
4 changed files with 27 additions and 21 deletions
+17
View File
@@ -146,4 +146,21 @@ module.exports = class CanvasUtil {
}
return { x, y, width, height };
}
static centerImagePart(data, maxWidth, maxHeight, widthOffset, heightOffest) {
let { width, height } = data;
if (width > maxWidth) {
const ratio = maxWidth / width;
width = maxWidth;
height *= ratio;
}
if (height > maxHeight) {
const ratio = maxHeight / height;
height = maxHeight;
width *= ratio;
}
const x = widthOffset + ((maxWidth / 2) - (width / 2));
const y = heightOffest + ((maxHeight / 2) - (height / 2));
return { x, y, width, height };
}
};