diff options
Diffstat (limited to 'internal/media')
| -rw-r--r-- | internal/media/processingmedia.go | 2 | ||||
| -rw-r--r-- | internal/media/thumbnail.go | 22 |
2 files changed, 11 insertions, 13 deletions
diff --git a/internal/media/processingmedia.go b/internal/media/processingmedia.go index a1305f104..0bb145a02 100644 --- a/internal/media/processingmedia.go +++ b/internal/media/processingmedia.go @@ -25,6 +25,7 @@ import ( "codeberg.org/gruf/go-kv" "codeberg.org/gruf/go-runners" + "code.superseriousbusiness.org/gotosocial/internal/config" "code.superseriousbusiness.org/gotosocial/internal/gtserror" "code.superseriousbusiness.org/gotosocial/internal/gtsmodel" "code.superseriousbusiness.org/gotosocial/internal/log" @@ -225,6 +226,7 @@ func (p *ProcessingMedia) store(ctx context.Context) error { if width > 0 && height > 0 { // Determine thumbnail dimens to use. thumbWidth, thumbHeight := thumbSize( + config.GetMediaThumbMaxPixels(), width, height, aspect, diff --git a/internal/media/thumbnail.go b/internal/media/thumbnail.go index 56247bc33..8493ba657 100644 --- a/internal/media/thumbnail.go +++ b/internal/media/thumbnail.go @@ -33,37 +33,33 @@ import ( "golang.org/x/image/webp" ) -const ( - maxThumbWidth = 512 - maxThumbHeight = 512 -) - // thumbSize returns the dimensions to use for an input // image of given width / height, for its outgoing thumbnail. // This attempts to maintains the original image aspect ratio. -func thumbSize(width, height int, aspect float32) (int, int) { +func thumbSize(max, width, height int, aspect float32) (int, int) { switch { // Simplest case, within bounds! - case width < maxThumbWidth && - height < maxThumbHeight: + case width < max && height < max: return width, height // Width is larger side. case width > height: + // i.e. height = newWidth * (height / width) - height = int(float32(maxThumbWidth) / aspect) - return maxThumbWidth, height + height = int(float32(max) / aspect) + return max, height // Height is larger side. case height > width: + // i.e. width = newHeight * (width / height) - width = int(float32(maxThumbHeight) * aspect) - return width, maxThumbHeight + width = int(float32(max) * aspect) + return width, max // Square. default: - return maxThumbWidth, maxThumbHeight + return max, max } } |
