pipeline.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package processing
  2. import (
  3. "context"
  4. "github.com/imgproxy/imgproxy/v3/imagedata"
  5. "github.com/imgproxy/imgproxy/v3/imagetype"
  6. "github.com/imgproxy/imgproxy/v3/options"
  7. "github.com/imgproxy/imgproxy/v3/vips"
  8. )
  9. type pipelineContext struct {
  10. ctx context.Context
  11. imgtype imagetype.Type
  12. trimmed bool
  13. srcWidth int
  14. srcHeight int
  15. angle int
  16. flip bool
  17. cropWidth int
  18. cropHeight int
  19. cropGravity options.GravityOptions
  20. wscale float64
  21. hscale float64
  22. iccImported bool
  23. }
  24. type pipelineStep func(pctx *pipelineContext, img *vips.Image, po *options.ProcessingOptions, imgdata *imagedata.ImageData) error
  25. type pipeline []pipelineStep
  26. func (p pipeline) Run(ctx context.Context, img *vips.Image, po *options.ProcessingOptions, imgdata *imagedata.ImageData) error {
  27. pctx := pipelineContext{
  28. ctx: ctx,
  29. wscale: 1.0,
  30. hscale: 1.0,
  31. cropGravity: po.Crop.Gravity,
  32. }
  33. if pctx.cropGravity.Type == options.GravityUnknown {
  34. pctx.cropGravity = po.Gravity
  35. }
  36. for _, step := range p {
  37. if err := step(&pctx, img, po, imgdata); err != nil {
  38. return err
  39. }
  40. }
  41. return nil
  42. }