mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-10-11 12:42:29 +02:00
Auto resizing type
This commit is contained in:
@@ -59,7 +59,8 @@ rt:%resizing_type
|
|||||||
Defines how imgproxy will resize the source image. Supported resizing types are:
|
Defines how imgproxy will resize the source image. Supported resizing types are:
|
||||||
|
|
||||||
* `fit`: resizes the image while keeping aspect ratio to fit given size;
|
* `fit`: resizes the image while keeping aspect ratio to fit given size;
|
||||||
* `fill`: resizes the image while keeping aspect ratio to fill given size and cropping projecting parts.
|
* `fill`: resizes the image while keeping aspect ratio to fill given size and cropping projecting parts;
|
||||||
|
* `auto`: if both source and resulting dimensions have the same orientation (portrait or landscape), imgproxy will use `fill`. Otherwise, it will use `fit`.
|
||||||
|
|
||||||
Default: `fit`
|
Default: `fit`
|
||||||
|
|
||||||
|
@@ -24,7 +24,8 @@ Once you set up your [URL signature](./configuration.md#url-signature), check ou
|
|||||||
imgproxy supports the following resizing types:
|
imgproxy supports the following resizing types:
|
||||||
|
|
||||||
* `fit`: resizes the image while keeping aspect ratio to fit given size;
|
* `fit`: resizes the image while keeping aspect ratio to fit given size;
|
||||||
* `fill`: resizes the image while keeping aspect ratio to fill given size and cropping projecting parts.
|
* `fill`: resizes the image while keeping aspect ratio to fill given size and cropping projecting parts;
|
||||||
|
* `auto`: if both source and resulting dimensions have the same orientation (portrait or landscape), imgproxy will use `fill`. Otherwise, it will use `fit`.
|
||||||
|
|
||||||
#### Width and height
|
#### Width and height
|
||||||
|
|
||||||
|
15
process.go
15
process.go
@@ -49,11 +49,24 @@ func calcScale(width, height int, po *processingOptions, imgtype imageType) floa
|
|||||||
wr := float64(po.Width) / srcW
|
wr := float64(po.Width) / srcW
|
||||||
hr := float64(po.Height) / srcH
|
hr := float64(po.Height) / srcH
|
||||||
|
|
||||||
|
rt := po.Resize
|
||||||
|
|
||||||
|
if rt == resizeAuto {
|
||||||
|
srcD := width - height
|
||||||
|
dstD := po.Width - po.Height
|
||||||
|
|
||||||
|
if (srcD >= 0 && dstD >= 0) || (srcD < 0 && dstD < 0) {
|
||||||
|
rt = resizeFill
|
||||||
|
} else {
|
||||||
|
rt = resizeFit
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if po.Width == 0 {
|
if po.Width == 0 {
|
||||||
scale = hr
|
scale = hr
|
||||||
} else if po.Height == 0 {
|
} else if po.Height == 0 {
|
||||||
scale = wr
|
scale = wr
|
||||||
} else if po.Resize == resizeFit {
|
} else if rt == resizeFit {
|
||||||
scale = math.Min(wr, hr)
|
scale = math.Min(wr, hr)
|
||||||
} else {
|
} else {
|
||||||
scale = math.Max(wr, hr)
|
scale = math.Max(wr, hr)
|
||||||
|
@@ -58,12 +58,14 @@ const (
|
|||||||
resizeFit resizeType = iota
|
resizeFit resizeType = iota
|
||||||
resizeFill
|
resizeFill
|
||||||
resizeCrop
|
resizeCrop
|
||||||
|
resizeAuto
|
||||||
)
|
)
|
||||||
|
|
||||||
var resizeTypes = map[string]resizeType{
|
var resizeTypes = map[string]resizeType{
|
||||||
"fit": resizeFit,
|
"fit": resizeFit,
|
||||||
"fill": resizeFill,
|
"fill": resizeFill,
|
||||||
"crop": resizeCrop,
|
"crop": resizeCrop,
|
||||||
|
"auto": resizeAuto,
|
||||||
}
|
}
|
||||||
|
|
||||||
type rgbColor struct{ R, G, B uint8 }
|
type rgbColor struct{ R, G, B uint8 }
|
||||||
|
Reference in New Issue
Block a user