Floor media dimensions to prevent blurhash errors (#8157)

pull/21833/head
Robin 2022-03-25 12:40:49 -04:00 committed by GitHub
parent bc01efa124
commit 3160442b8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View File

@ -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) };
}
}

View File

@ -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 });
});
});
});