Compare commits

...

3 Commits

Author SHA1 Message Date
73b80a66bc v0.0.459
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 1m16s
2024-05-20 00:20:31 +02:00
d8b2d01274 v0.0.458 revert 457 and fix ObjectFitImage
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 2m49s
2024-05-20 00:15:24 +02:00
bfa8457e95 v0.0.457 test
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 3m38s
2024-05-20 00:07:33 +02:00
2 changed files with 9 additions and 5 deletions

View File

@@ -1,5 +1,5 @@
package goext package goext
const GoextVersion = "0.0.456" const GoextVersion = "0.0.459"
const GoextVersionTimestamp = "2024-05-18T23:38:47+0200" const GoextVersionTimestamp = "2024-05-20T00:20:31+0200"

View File

@@ -234,11 +234,15 @@ func ObjectFitImage(img image.Image, bbw float64, bbh float64, fit ImageFit, fil
// we scale the bounding box by fac (both dimension the same amount, to keep the bounding-box ratio) // we scale the bounding box by fac (both dimension the same amount, to keep the bounding-box ratio)
// [ow|oh] ==> size of output image (same ratio as bounding box [bbw|bbh])
ow := int(math.Round(bbw * facOut)) ow := int(math.Round(bbw * facOut))
oh := int(math.Round(bbh * facOut)) oh := int(math.Round(bbh * facOut))
facScale := mathext.Min(float64(ow)/float64(iw), float64(oh)/float64(ih)) facScale := mathext.Min(float64(ow)/float64(iw), float64(oh)/float64(ih))
// [dw|dh] ==> size of destination rect (where to draw source in output image) (same ratio as input image [iw|ih])
dw := int(math.Round(float64(iw) * facScale)) dw := int(math.Round(float64(iw) * facScale))
dh := int(math.Round(float64(ih) * facScale)) dh := int(math.Round(float64(ih) * facScale))
@@ -248,11 +252,11 @@ func ObjectFitImage(img image.Image, bbw float64, bbh float64, fit ImageFit, fil
if fit == ImageFitContainCenter { if fit == ImageFitContainCenter {
destBounds = image.Rect((ow-dw)/2, (oh-dh)/2, (ow-dw)/2+dw, (oh-dh)/2+dh) destBounds = image.Rect((ow-dw)/2, (oh-dh)/2, (ow-dw)/2+dw, (oh-dh)/2+dh)
} else if fit == ImageFitContainTopLeft { } else if fit == ImageFitContainTopLeft {
destBounds = image.Rect(0, 0, iw, dh) destBounds = image.Rect(0, 0, dw, dh)
} else if fit == ImageFitContainTopRight { } else if fit == ImageFitContainTopRight {
destBounds = image.Rect(ow-iw, 0, ow, dh) destBounds = image.Rect(ow-dw, 0, ow, dh)
} else if fit == ImageFitContainBottomLeft { } else if fit == ImageFitContainBottomLeft {
destBounds = image.Rect(0, oh-dh, iw, oh) destBounds = image.Rect(0, oh-dh, dw, oh)
} else if fit == ImageFitContainBottomRight { } else if fit == ImageFitContainBottomRight {
destBounds = image.Rect(ow-dw, oh-dh, ow, oh) destBounds = image.Rect(ow-dw, oh-dh, ow, oh)
} }