mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-26 22:32:52 +02:00
Fix
This commit is contained in:
@@ -134,13 +134,22 @@ module.exports = class ChallengerCommand extends Command {
|
|||||||
centerInBox(ctx, img, boxX, boxY, boxWidth, boxHeight) {
|
centerInBox(ctx, img, boxX, boxY, boxWidth, boxHeight) {
|
||||||
const imgAspectRatio = img.width / img.height;
|
const imgAspectRatio = img.width / img.height;
|
||||||
const boxAspectRatio = boxWidth / boxHeight;
|
const boxAspectRatio = boxWidth / boxHeight;
|
||||||
let drawWidth, drawHeight;
|
let drawWidth;
|
||||||
|
let drawHeight;
|
||||||
if (imgAspectRatio > boxAspectRatio) {
|
if (imgAspectRatio > boxAspectRatio) {
|
||||||
drawHeight = boxHeight;
|
|
||||||
drawWidth = img.width * (drawHeight / img.height);
|
|
||||||
} else {
|
|
||||||
drawWidth = boxWidth;
|
drawWidth = boxWidth;
|
||||||
drawHeight = img.height * (drawWidth / img.width);
|
drawHeight = drawWidth / imgAspectRatio;
|
||||||
|
if (drawHeight > boxHeight) {
|
||||||
|
drawHeight = boxHeight;
|
||||||
|
drawWidth = drawHeight * imgAspectRatio;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
drawHeight = boxHeight;
|
||||||
|
drawWidth = drawHeight * imgAspectRatio;
|
||||||
|
if (drawWidth > boxWidth) {
|
||||||
|
drawWidth = boxWidth;
|
||||||
|
drawHeight = drawWidth / imgAspectRatio;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const drawX = boxX + ((boxWidth - drawWidth) / 2);
|
const drawX = boxX + ((boxWidth - drawWidth) / 2);
|
||||||
const drawY = boxY + ((boxHeight - drawHeight) / 2);
|
const drawY = boxY + ((boxHeight - drawHeight) / 2);
|
||||||
|
|||||||
Reference in New Issue
Block a user