mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-10-09 19:52:30 +02:00
Add zoom option
This commit is contained in:
@@ -53,8 +53,7 @@ func crop(pctx *pipelineContext, img *vips.Image, po *options.ProcessingOptions,
|
||||
|
||||
func cropToResult(pctx *pipelineContext, img *vips.Image, po *options.ProcessingOptions, imgdata *imagedata.ImageData) error {
|
||||
// Crop image to the result size
|
||||
resultWidth := imath.Scale(po.Width, po.Dpr)
|
||||
resultHeight := imath.Scale(po.Height, po.Dpr)
|
||||
resultWidth, resultHeight := resultSize(po)
|
||||
|
||||
if po.ResizingType == options.ResizeFillDown {
|
||||
if resultWidth > img.Width() {
|
||||
|
@@ -2,14 +2,12 @@ package processing
|
||||
|
||||
import (
|
||||
"github.com/imgproxy/imgproxy/v3/imagedata"
|
||||
"github.com/imgproxy/imgproxy/v3/imath"
|
||||
"github.com/imgproxy/imgproxy/v3/options"
|
||||
"github.com/imgproxy/imgproxy/v3/vips"
|
||||
)
|
||||
|
||||
func extend(pctx *pipelineContext, img *vips.Image, po *options.ProcessingOptions, imgdata *imagedata.ImageData) error {
|
||||
resultWidth := imath.Scale(po.Width, po.Dpr)
|
||||
resultHeight := imath.Scale(po.Height, po.Dpr)
|
||||
resultWidth, resultHeight := resultSize(po)
|
||||
|
||||
if !po.Extend.Enabled || (resultWidth <= img.Width() && resultHeight <= img.Height()) {
|
||||
return nil
|
||||
|
@@ -98,6 +98,9 @@ func calcScale(width, height int, po *options.ProcessingOptions, imgtype imagety
|
||||
}
|
||||
}
|
||||
|
||||
wshrink /= po.ZoomWidth
|
||||
hshrink /= po.ZoomHeight
|
||||
|
||||
if !po.Enlarge && imgtype != imagetype.SVG {
|
||||
if wshrink < 1 {
|
||||
hshrink /= wshrink
|
||||
|
13
processing/result_size.go
Normal file
13
processing/result_size.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package processing
|
||||
|
||||
import (
|
||||
"github.com/imgproxy/imgproxy/v3/imath"
|
||||
"github.com/imgproxy/imgproxy/v3/options"
|
||||
)
|
||||
|
||||
func resultSize(po *options.ProcessingOptions) (int, int) {
|
||||
resultWidth := imath.Scale(po.Width, po.Dpr*po.ZoomWidth)
|
||||
resultHeight := imath.Scale(po.Height, po.Dpr*po.ZoomHeight)
|
||||
|
||||
return resultWidth, resultHeight
|
||||
}
|
Reference in New Issue
Block a user