@uppy/thumbnail-generator: don't enlarge already small thumbnails (#4406)

- Thumbnail shouldn’t be enlarged / upscaled, only reduced. If img is
already smaller than width/height, leave it as is. @nqst reported this
in
https://github.com/transloadit/uppy/pull/4374#pullrequestreview-1361065165
- We have image width/height when we resize for thumbnail, might as well
set it as file.meta for Uppy users and us to use in the UI?

Before:
![Screen Shot 2023-04-07 at 01 57
55](https://user-images.githubusercontent.com/1199054/230519313-ac8c86e1-4c04-4f9d-a19b-480e0215452f.png)

After:
![Screen Shot 2023-04-07 at 01 56
55](https://user-images.githubusercontent.com/1199054/230519337-55890d39-8091-4038-b897-483e452fcf55.png)

---------

Co-authored-by: Mikael Finstad <finstaden@gmail.com>
Co-authored-by: Merlijn Vos <merlijn@soverin.net>
This commit is contained in:
Artur Paikin 2025-08-19 13:40:13 +01:00 committed by GitHub
parent 57f7867c41
commit 79502f7646
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 4 deletions

View file

@ -0,0 +1,5 @@
---
"@uppy/thumbnail-generator": patch
---
Make tiny/small thumbnails look better by not scaling them to cover the entire grid item

View file

@ -258,16 +258,23 @@ export default class ThumbnailGenerator<
}
if (width != null) {
let targetWidth = width
// Thumbnail shouldnt be enlarged / upscaled, only reduced.
// If img is already smaller than width/height, leave it as is.
if (img.width < width) targetWidth = img.width
return {
width,
height: Math.round(width / aspect),
width: targetWidth,
height: Math.round(targetWidth / aspect),
}
}
if (height != null) {
let targetHeight = height
if (img.height < height) targetHeight = img.height
return {
width: Math.round(height * aspect),
height,
width: Math.round(targetHeight * aspect),
height: targetHeight,
}
}