mirror of
https://github.com/transloadit/uppy.git
synced 2026-01-23 02:25:07 +00:00
@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:  After:  --------- Co-authored-by: Mikael Finstad <finstaden@gmail.com> Co-authored-by: Merlijn Vos <merlijn@soverin.net>
This commit is contained in:
parent
57f7867c41
commit
79502f7646
2 changed files with 16 additions and 4 deletions
5
.changeset/warm-bulldogs-relate.md
Normal file
5
.changeset/warm-bulldogs-relate.md
Normal 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
|
||||
|
|
@ -258,16 +258,23 @@ export default class ThumbnailGenerator<
|
|||
}
|
||||
|
||||
if (width != null) {
|
||||
let targetWidth = width
|
||||
// Thumbnail shouldn’t 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,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue