1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2025-12-03 23:19:17 +02:00

Crop by percentage

This commit is contained in:
DarthSim
2021-01-18 21:14:15 +06:00
parent e48c557fc4
commit 9ffb0f514d
4 changed files with 36 additions and 11 deletions

View File

@@ -95,8 +95,8 @@ type extendOptions struct {
}
type cropOptions struct {
Width int
Height int
Width float64
Height float64
Gravity gravityOptions
}
@@ -571,13 +571,17 @@ func applyCropOption(po *processingOptions, args []string) error {
return fmt.Errorf("Invalid crop arguments: %v", args)
}
if err := parseDimension(&po.Crop.Width, "crop width", args[0]); err != nil {
return err
if w, err := strconv.ParseFloat(args[0], 64); err == nil && w >= 0 {
po.Crop.Width = w
} else {
return fmt.Errorf("Invalid crop width: %s", args[0])
}
if len(args) > 1 {
if err := parseDimension(&po.Crop.Height, "crop height", args[1]); err != nil {
return err
if h, err := strconv.ParseFloat(args[1], 64); err == nil && h >= 0 {
po.Crop.Height = h
} else {
return fmt.Errorf("Invalid crop height: %s", args[1])
}
}