add boundaries for autocrop to allow split then crop

This commit is contained in:
Celogeek 2024-01-28 16:43:54 +01:00
parent 2442f2edc7
commit 51f62588c2
Signed by: celogeek
SSH Key Fingerprint: SHA256:DEDfxIK2nUWXbslbRkww3zsauDjhWHlTXar+ak4lDJ4

View File

@ -8,9 +8,9 @@ import (
) )
// Lookup for margin and crop // Lookup for margin and crop
func AutoCrop(img image.Image, cutRatioLeft, cutRatioUp, cutRatioRight, cutRatioBottom int) gift.Filter { func AutoCrop(img image.Image, bounds image.Rectangle, cutRatioLeft, cutRatioUp, cutRatioRight, cutRatioBottom int) gift.Filter {
return gift.Crop( return gift.Crop(
findMarging(img, cutRatioOptions{cutRatioLeft, cutRatioUp, cutRatioRight, cutRatioBottom}), findMargin(img, bounds, cutRatioOptions{cutRatioLeft, cutRatioUp, cutRatioRight, cutRatioBottom}),
) )
} }
@ -25,8 +25,8 @@ type cutRatioOptions struct {
Left, Up, Right, Bottom int Left, Up, Right, Bottom int
} }
func findMarging(img image.Image, cutRatio cutRatioOptions) image.Rectangle { func findMargin(img image.Image, bounds image.Rectangle, cutRatio cutRatioOptions) image.Rectangle {
imgArea := img.Bounds() imgArea := bounds
LEFT: LEFT:
for x := imgArea.Min.X; x < imgArea.Max.X; x++ { for x := imgArea.Min.X; x < imgArea.Max.X; x++ {