fit=outside works both sides out again from the larger scale, and a side scaled to 1 could come out just under 1 and round down to 0, which libvips refuses: a 49x8192 source at 0x100 and a 49x49 source at 1x1 answered 500. README.md now says what fit=outside does, with the 8192x1 source at 100x0 that comes out at 8192x1, and how a 0 side is worked out from the source's proportions. Model: opus-5-5
This commit is contained in:
@@ -514,13 +514,16 @@ func (p *ImageProcessor) resize(
|
||||
return img.Thumbnail(newW, newH, vips.InterestingNone)
|
||||
|
||||
case FitOutside:
|
||||
// Resize so smallest dimension fits, may exceed target on other dimension
|
||||
// Resize so smallest dimension fits, may exceed target on other
|
||||
// dimension. A side scaled to 1 can come out just under 1 in
|
||||
// floating point, as 49 times 1/49 does, and round down to 0, which
|
||||
// libvips refuses as a width, so each side is at least 1.
|
||||
imgW, imgH := img.Width(), img.Height()
|
||||
scaleW := float64(width) / float64(imgW)
|
||||
scaleH := float64(height) / float64(imgH)
|
||||
scale := max(scaleW, scaleH)
|
||||
newW := int(float64(imgW) * scale)
|
||||
newH := int(float64(imgH) * scale)
|
||||
newW := max(1, int(float64(imgW)*scale))
|
||||
newH := max(1, int(float64(imgH)*scale))
|
||||
|
||||
// The dimension that exceeds the target is held to the maximum too
|
||||
if newW > MaxOutputDimension || newH > MaxOutputDimension {
|
||||
|
||||
Reference in New Issue
Block a user