diff --git a/src/github.com/turt2live/matrix-media-repo/media_handler/thumbnailer.go b/src/github.com/turt2live/matrix-media-repo/media_handler/thumbnailer.go index b6ffc8e461b487bd8a212d12ce31a5dd1253090e..7dc62fa4b72708073f50119256a1cc802a10f6e9 100644 --- a/src/github.com/turt2live/matrix-media-repo/media_handler/thumbnailer.go +++ b/src/github.com/turt2live/matrix-media-repo/media_handler/thumbnailer.go @@ -31,6 +31,7 @@ func GetThumbnail(ctx context.Context, media types.Media, width int, height int, for i := 0; i < len(c.Thumbnails.Sizes); i++ { size := c.Thumbnails.Sizes[i] + lastSize := i == len(c.Thumbnails.Sizes) - 1 if width == size.Width && height == size.Height { targetWidth = width @@ -38,7 +39,7 @@ func GetThumbnail(ctx context.Context, media types.Media, width int, height int, break } - if size.Width < width || size.Height < height { + if (size.Width < width || size.Height < height) && !lastSize { continue // too small } @@ -50,7 +51,7 @@ func GetThumbnail(ctx context.Context, media types.Media, width int, height int, diff := diffWidth + diffHeight currDiff := currDiffWidth + currDiffHeight - if !foundFirst || diff < currDiff { + if !foundFirst || diff < currDiff || lastSize { foundFirst = true targetWidth = size.Width targetHeight = size.Height