Skip to content

Commit 3160442

Browse files
authored
Floor media dimensions to prevent blurhash errors (matrix-org#8157)
1 parent bc01efa commit 3160442

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/settings/enums/ImageSize.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ export function suggestedSize(size: ImageSize, contentSize: Dimensions, maxHeigh
5252

5353
if (constrainedSize.h * aspectRatio < constrainedSize.w) {
5454
// Height dictates width
55-
return { w: constrainedSize.h * aspectRatio, h: constrainedSize.h };
55+
return { w: Math.floor(constrainedSize.h * aspectRatio), h: constrainedSize.h };
5656
} else {
5757
// Width dictates height
58-
return { w: constrainedSize.w, h: constrainedSize.w / aspectRatio };
58+
return { w: constrainedSize.w, h: Math.floor(constrainedSize.w / aspectRatio) };
5959
}
6060
}

test/settings/enums/ImageSize-test.ts

+4
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,9 @@ describe("ImageSize", () => {
3434
const size = suggestedSize(ImageSize.Normal, { w: null, h: null });
3535
expect(size).toStrictEqual({ w: 324, h: 324 });
3636
});
37+
it("returns integer values", () => {
38+
const size = suggestedSize(ImageSize.Normal, { w: 642, h: 350 }); // does not divide evenly
39+
expect(size).toStrictEqual({ w: 324, h: 176 });
40+
});
3741
});
3842
});

0 commit comments

Comments
 (0)