Skip to content

Commit a6c7555

Browse files
committed
fix: Floor offset calculation
1 parent 725e078 commit a6c7555

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

cli.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,25 @@ const cropGif = async path => {
107107
const { width: newWidth, height: newHeight } = await sharp(
108108
resized
109109
).metadata();
110+
// console.log({ newWidth, newHeight });
110111

111-
const offsetX = (newWidth - CONTAINER_WIDTH) / 2;
112-
const offsetY = (newHeight - MINIMUM_HEIGHT) / 2;
112+
const offsetX = Math.floor((newWidth - CONTAINER_WIDTH) / 2);
113+
const offsetY = Math.floor((newHeight - MINIMUM_HEIGHT) / 2);
113114
const files = [];
114115
for (let i = 0; i < 6; i++) {
115116
const filename = `${name}.${i}.gif`;
116117
const { x, y } = getXY(i);
118+
const xPos = x + offsetX;
119+
const yPos = y + offsetY;
120+
// console.log({
121+
// xPos,
122+
// yPos,
123+
// CUT_WIDTH,
124+
// CUT_HEIGHT
125+
// });
117126
await execa(gifsicle, [
118127
"--crop",
119-
`${x + offsetX},${y + offsetY}+${CUT_WIDTH}x${CUT_HEIGHT}`,
128+
`${xPos},${yPos}+${CUT_WIDTH}x${CUT_HEIGHT}`,
120129
"-o",
121130
filename,
122131
resized

0 commit comments

Comments
 (0)