From 3160442b8b65d26f0f11f6ae6be666fd20cf0124 Mon Sep 17 00:00:00 2001 From: Robin Date: Fri, 25 Mar 2022 12:40:49 -0400 Subject: [PATCH] Floor media dimensions to prevent blurhash errors (#8157) --- src/settings/enums/ImageSize.ts | 4 ++-- test/settings/enums/ImageSize-test.ts | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/settings/enums/ImageSize.ts b/src/settings/enums/ImageSize.ts index ed59723d04..93cc236273 100644 --- a/src/settings/enums/ImageSize.ts +++ b/src/settings/enums/ImageSize.ts @@ -52,9 +52,9 @@ export function suggestedSize(size: ImageSize, contentSize: Dimensions, maxHeigh if (constrainedSize.h * aspectRatio < constrainedSize.w) { // Height dictates width - return { w: constrainedSize.h * aspectRatio, h: constrainedSize.h }; + return { w: Math.floor(constrainedSize.h * aspectRatio), h: constrainedSize.h }; } else { // Width dictates height - return { w: constrainedSize.w, h: constrainedSize.w / aspectRatio }; + return { w: constrainedSize.w, h: Math.floor(constrainedSize.w / aspectRatio) }; } } diff --git a/test/settings/enums/ImageSize-test.ts b/test/settings/enums/ImageSize-test.ts index 97da1fbe20..55de23f924 100644 --- a/test/settings/enums/ImageSize-test.ts +++ b/test/settings/enums/ImageSize-test.ts @@ -34,5 +34,9 @@ describe("ImageSize", () => { const size = suggestedSize(ImageSize.Normal, { w: null, h: null }); 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 }); + }); }); });