1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2025-01-18 11:12:10 +02:00
imgproxy/processing/pipeline.go

68 lines
1.3 KiB
Go
Raw Normal View History

2021-04-26 17:52:50 +06:00
package processing
import (
"context"
2021-09-30 20:23:30 +06:00
"github.com/imgproxy/imgproxy/v3/imagedata"
"github.com/imgproxy/imgproxy/v3/imagetype"
"github.com/imgproxy/imgproxy/v3/options"
2022-06-23 17:23:04 +06:00
"github.com/imgproxy/imgproxy/v3/router"
2021-09-30 20:23:30 +06:00
"github.com/imgproxy/imgproxy/v3/vips"
2021-04-26 17:52:50 +06:00
)
type pipelineContext struct {
ctx context.Context
imgtype imagetype.Type
trimmed bool
srcWidth int
srcHeight int
angle int
flip bool
cropWidth int
cropHeight int
cropGravity options.GravityOptions
wscale float64
hscale float64
dprScale float64
2021-04-26 17:52:50 +06:00
iccImported bool
}
type pipelineStep func(pctx *pipelineContext, img *vips.Image, po *options.ProcessingOptions, imgdata *imagedata.ImageData) error
type pipeline []pipelineStep
func (p pipeline) Run(ctx context.Context, img *vips.Image, po *options.ProcessingOptions, imgdata *imagedata.ImageData) error {
pctx := pipelineContext{
ctx: ctx,
wscale: 1.0,
hscale: 1.0,
cropGravity: po.Crop.Gravity,
}
if pctx.cropGravity.Type == options.GravityUnknown {
pctx.cropGravity = po.Gravity
}
for _, step := range p {
if err := step(&pctx, img, po, imgdata); err != nil {
return err
}
2022-07-20 15:49:05 +06:00
if err := router.CheckTimeout(ctx); err != nil {
return err
}
2021-04-26 17:52:50 +06:00
}
img.SetDouble("imgproxy-dpr-scale", pctx.dprScale)
2021-04-26 17:52:50 +06:00
return nil
}