mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 15:07:42 +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) {
|
||||
const imgAspectRatio = img.width / img.height;
|
||||
const boxAspectRatio = boxWidth / boxHeight;
|
||||
let drawWidth;
|
||||
const boxAspectRatio = boxWidth / boxHeight;
|
||||
let drawWidth;
|
||||
let drawHeight;
|
||||
if (imgAspectRatio > boxAspectRatio) {
|
||||
drawWidth = boxWidth;
|
||||
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 drawY = boxY + ((boxHeight - drawHeight) / 2);
|
||||
if (imgAspectRatio > boxAspectRatio) {
|
||||
drawWidth = boxWidth;
|
||||
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 drawY = boxY + ((boxHeight - drawHeight) / 2);
|
||||
return { x: drawX, y: drawY, width: drawWidth, height: drawHeight };
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user