1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2025-02-12 11:46:10 +02:00

properly parse boolean processing options

This commit is contained in:
DarthSim 2019-11-11 18:58:45 +06:00
parent 557b3a63e9
commit ba3e20b865
4 changed files with 19 additions and 7 deletions

View File

@ -1,6 +1,8 @@
# Changelog
## [Unreleased]
### Changed
- Boolean processing options such as `enlarge` and `extend` are properly parsed. `1`, `t`, `TRUE`, `true`, `True` are truthy, `0`, `f`, `F`, `FALSE`, `false`, `False` are falsy. All other values are treated as falsy and generate a warning message.
## [2.6.2] - 2019-11-11
### Fixed

View File

@ -103,9 +103,9 @@ enlarge:%enlarge
el:%enlarge
```
If set to `0`, imgproxy will not enlarge the image if it is smaller than the given size. With any other value, imgproxy will enlarge the image.
When set to `1`, `t` or `true`, imgproxy will enlarge the image if it is smaller than the given size.
Default: `0`
Default: false
#### Extend
@ -114,9 +114,9 @@ extend:%extend
ex:%extend
```
If set to `0`, imgproxy will not extend the image if the resizing result is smaller than the given size. With any other value, imgproxy will extend the image to the given size.
When set to `1`, `t` or `true`, imgproxy will extend the image if it is smaller than the given size.
Default: `0`
Default: false
#### Gravity

View File

@ -49,7 +49,7 @@ When imgproxy needs to cut some parts of the image, it is guided by the gravity.
### Enlarge
When set to `0`, imgproxy will not enlarge the image if it is smaller than the given size. With any other value, imgproxy will enlarge the image.
When set to `1`, `t` or `true`, imgproxy will enlarge the image if it is smaller than the given size.
### Source URL

View File

@ -330,6 +330,16 @@ func parseDimension(d *int, name, arg string) error {
return nil
}
func parseBoolOption(str string) bool {
b, err := strconv.ParseBool(str)
if err != nil {
logWarning("`%s` is not a valid boolean value. Treated as false", str)
}
return b
}
func isGravityOffcetValid(gravity gravityType, offset float64) bool {
if gravity == gravityCenter {
return true
@ -397,7 +407,7 @@ func applyEnlargeOption(po *processingOptions, args []string) error {
return fmt.Errorf("Invalid enlarge arguments: %v", args)
}
po.Enlarge = args[0] != "0"
po.Enlarge = parseBoolOption(args[0])
return nil
}
@ -407,7 +417,7 @@ func applyExtendOption(po *processingOptions, args []string) error {
return fmt.Errorf("Invalid extend arguments: %v", args)
}
po.Extend = args[0] != "0"
po.Extend = parseBoolOption(args[0])
return nil
}