You've already forked imgproxy
mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-12-09 23:41:58 +02:00
min-width and min-height processing options
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
- [skip processing](https://docs.imgproxy.net/#/generating_the_url?id=skip-processing) processing option.
|
- [skip processing](https://docs.imgproxy.net/#/generating_the_url?id=skip-processing) processing option.
|
||||||
- [Datadog](./docs/datadog.md) metrics.
|
- [Datadog](./docs/datadog.md) metrics.
|
||||||
- `force` and `fill-down` resizing types.
|
- `force` and `fill-down` resizing types.
|
||||||
|
- [min-width](https://docs.imgproxy.net/#/generating_the_url?id=min-width) and [min-height](https://docs.imgproxy.net/#/generating_the_url?id=min-height) processing options.
|
||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
- Removed basic URL format, use [advanced one](./docs/generating_the_url.md) instead.
|
- Removed basic URL format, use [advanced one](./docs/generating_the_url.md) instead.
|
||||||
|
|||||||
@@ -95,6 +95,32 @@ Defines the height of the resulting image. When set to `0`, imgproxy will calcul
|
|||||||
|
|
||||||
Default: `0`
|
Default: `0`
|
||||||
|
|
||||||
|
### Min width
|
||||||
|
|
||||||
|
```
|
||||||
|
min-width:%width
|
||||||
|
mw:%width
|
||||||
|
```
|
||||||
|
|
||||||
|
Defines the minimum width of the resulting image.
|
||||||
|
|
||||||
|
**⚠️Warning:** When both `width` and `min-width` are set, the final image will be cropped according to `width`, so use this combination with care.
|
||||||
|
|
||||||
|
Default: `0`
|
||||||
|
|
||||||
|
### Min height
|
||||||
|
|
||||||
|
```
|
||||||
|
min-height:%height
|
||||||
|
mh:%height
|
||||||
|
```
|
||||||
|
|
||||||
|
Defines the minimum height of the resulting image.
|
||||||
|
|
||||||
|
**⚠️Warning:** When both `height` and `min-height` are set, the final image will be cropped according to `height`, so use this combination with care.
|
||||||
|
|
||||||
|
Default: `0`
|
||||||
|
|
||||||
### Dpr
|
### Dpr
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|||||||
14
process.go
14
process.go
@@ -135,6 +135,20 @@ func calcScale(width, height int, po *processingOptions, imgtype imageType) (flo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if po.MinWidth > 0 {
|
||||||
|
if minShrink := srcW / float64(po.MinWidth); minShrink < wshrink {
|
||||||
|
hshrink /= wshrink / minShrink
|
||||||
|
wshrink = minShrink
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if po.MinHeight > 0 {
|
||||||
|
if minShrink := srcH / float64(po.MinHeight); minShrink < hshrink {
|
||||||
|
wshrink /= hshrink / minShrink
|
||||||
|
hshrink = minShrink
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
wshrink /= po.Dpr
|
wshrink /= po.Dpr
|
||||||
hshrink /= po.Dpr
|
hshrink /= po.Dpr
|
||||||
|
|
||||||
|
|||||||
@@ -132,6 +132,8 @@ type processingOptions struct {
|
|||||||
ResizingType resizeType
|
ResizingType resizeType
|
||||||
Width int
|
Width int
|
||||||
Height int
|
Height int
|
||||||
|
MinWidth int
|
||||||
|
MinHeight int
|
||||||
Dpr float64
|
Dpr float64
|
||||||
Gravity gravityOptions
|
Gravity gravityOptions
|
||||||
Enlarge bool
|
Enlarge bool
|
||||||
@@ -461,6 +463,22 @@ func applyHeightOption(po *processingOptions, args []string) error {
|
|||||||
return parseDimension(&po.Height, "height", args[0])
|
return parseDimension(&po.Height, "height", args[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func applyMinWidthOption(po *processingOptions, args []string) error {
|
||||||
|
if len(args) > 1 {
|
||||||
|
return fmt.Errorf("Invalid min width arguments: %v", args)
|
||||||
|
}
|
||||||
|
|
||||||
|
return parseDimension(&po.MinWidth, "min width", args[0])
|
||||||
|
}
|
||||||
|
|
||||||
|
func applyMinHeightOption(po *processingOptions, args []string) error {
|
||||||
|
if len(args) > 1 {
|
||||||
|
return fmt.Errorf("Invalid min height arguments: %v", args)
|
||||||
|
}
|
||||||
|
|
||||||
|
return parseDimension(&po.MinHeight, " min height", args[0])
|
||||||
|
}
|
||||||
|
|
||||||
func applyEnlargeOption(po *processingOptions, args []string) error {
|
func applyEnlargeOption(po *processingOptions, args []string) error {
|
||||||
if len(args) > 1 {
|
if len(args) > 1 {
|
||||||
return fmt.Errorf("Invalid enlarge arguments: %v", args)
|
return fmt.Errorf("Invalid enlarge arguments: %v", args)
|
||||||
@@ -970,6 +988,10 @@ func applyProcessingOption(po *processingOptions, name string, args []string) er
|
|||||||
return applyWidthOption(po, args)
|
return applyWidthOption(po, args)
|
||||||
case "height", "h":
|
case "height", "h":
|
||||||
return applyHeightOption(po, args)
|
return applyHeightOption(po, args)
|
||||||
|
case "min-width", "mw":
|
||||||
|
return applyMinWidthOption(po, args)
|
||||||
|
case "min-height", "mh":
|
||||||
|
return applyMinHeightOption(po, args)
|
||||||
case "enlarge", "el":
|
case "enlarge", "el":
|
||||||
return applyEnlargeOption(po, args)
|
return applyEnlargeOption(po, args)
|
||||||
case "extend", "ex":
|
case "extend", "ex":
|
||||||
|
|||||||
Reference in New Issue
Block a user