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.
This commit is contained in:
2026-01-08 12:20:58 -08:00
parent 817d760b4d
commit 10b5cc7063

View File

@@ -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