From 10b5cc7063758341529d1624dd0610a8d6dc6233 Mon Sep 17 00:00:00 2001 From: sneak Date: Thu, 8 Jan 2026 12:20:58 -0800 Subject: [PATCH] Fix proportional scaling when single dimension is 0 When only width or height is specified (the other being 0), scale the image proportionally to maintain aspect ratio. Previously, 0 was passed directly to the resize function which produced a 0x0 image. --- internal/imgcache/processor.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/internal/imgcache/processor.go b/internal/imgcache/processor.go index 75f81f6..ca2a60f 100644 --- a/internal/imgcache/processor.go +++ b/internal/imgcache/processor.go @@ -66,10 +66,17 @@ func (p *ImageProcessor) Process( targetWidth := req.Size.Width targetHeight := req.Size.Height - // If both are 0, keep original size + // Handle dimension calculation if targetWidth == 0 && targetHeight == 0 { + // Both are 0: keep original size targetWidth = origWidth targetHeight = origHeight + } else if targetWidth == 0 { + // Only height specified: calculate width proportionally + targetWidth = origWidth * targetHeight / origHeight + } else if targetHeight == 0 { + // Only width specified: calculate height proportionally + targetHeight = origHeight * targetWidth / origWidth } // Resize if needed