You've already forked matrix-react-sdk
mirror of
https://github.com/matrix-org/matrix-react-sdk.git
synced 2025-08-04 23:02:14 +03:00
Floor media dimensions to prevent blurhash errors (#8157)
This commit is contained in:
@@ -52,9 +52,9 @@ export function suggestedSize(size: ImageSize, contentSize: Dimensions, maxHeigh
|
|||||||
|
|
||||||
if (constrainedSize.h * aspectRatio < constrainedSize.w) {
|
if (constrainedSize.h * aspectRatio < constrainedSize.w) {
|
||||||
// Height dictates width
|
// Height dictates width
|
||||||
return { w: constrainedSize.h * aspectRatio, h: constrainedSize.h };
|
return { w: Math.floor(constrainedSize.h * aspectRatio), h: constrainedSize.h };
|
||||||
} else {
|
} else {
|
||||||
// Width dictates height
|
// Width dictates height
|
||||||
return { w: constrainedSize.w, h: constrainedSize.w / aspectRatio };
|
return { w: constrainedSize.w, h: Math.floor(constrainedSize.w / aspectRatio) };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -34,5 +34,9 @@ describe("ImageSize", () => {
|
|||||||
const size = suggestedSize(ImageSize.Normal, { w: null, h: null });
|
const size = suggestedSize(ImageSize.Normal, { w: null, h: null });
|
||||||
expect(size).toStrictEqual({ w: 324, h: 324 });
|
expect(size).toStrictEqual({ w: 324, h: 324 });
|
||||||
});
|
});
|
||||||
|
it("returns integer values", () => {
|
||||||
|
const size = suggestedSize(ImageSize.Normal, { w: 642, h: 350 }); // does not divide evenly
|
||||||
|
expect(size).toStrictEqual({ w: 324, h: 176 });
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user