mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-25 22:32:50 +02:00
Fix
This commit is contained in:
+19
-19
@@ -277,26 +277,26 @@ module.exports = class CanvasUtil {
|
|||||||
|
|
||||||
static centerImagePart(img, boxWidth, boxHeight, boxX, boxY) {
|
static centerImagePart(img, boxWidth, boxHeight, boxX, boxY) {
|
||||||
const imgAspectRatio = img.width / img.height;
|
const imgAspectRatio = img.width / img.height;
|
||||||
const boxAspectRatio = boxWidth / boxHeight;
|
const boxAspectRatio = boxWidth / boxHeight;
|
||||||
let drawWidth;
|
let drawWidth;
|
||||||
let drawHeight;
|
let drawHeight;
|
||||||
if (imgAspectRatio > boxAspectRatio) {
|
if (imgAspectRatio > boxAspectRatio) {
|
||||||
drawWidth = boxWidth;
|
drawWidth = boxWidth;
|
||||||
drawHeight = drawWidth / imgAspectRatio;
|
drawHeight = drawWidth / imgAspectRatio;
|
||||||
if (drawHeight > boxHeight) {
|
if (drawHeight > boxHeight) {
|
||||||
drawHeight = boxHeight;
|
drawHeight = boxHeight;
|
||||||
drawWidth = drawHeight * imgAspectRatio;
|
drawWidth = drawHeight * imgAspectRatio;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
drawHeight = boxHeight;
|
drawHeight = boxHeight;
|
||||||
drawWidth = drawHeight * imgAspectRatio;
|
drawWidth = drawHeight * imgAspectRatio;
|
||||||
if (drawWidth > boxWidth) {
|
if (drawWidth > boxWidth) {
|
||||||
drawWidth = boxWidth;
|
drawWidth = boxWidth;
|
||||||
drawHeight = drawWidth / imgAspectRatio;
|
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);
|
||||||
return { x: drawX, y: drawY, width: drawWidth, height: drawHeight };
|
return { x: drawX, y: drawY, width: drawWidth, height: drawHeight };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user