Add zoom option

This commit is contained in:
DarthSim
2022-01-18 16:09:32 +06:00
parent 41f3ce1e06
commit fff164f45a
7 changed files with 70 additions and 5 deletions

View File

@@ -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() {

View File

@@ -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

View File

@@ -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
View 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
}