Micro-service for file storage and processing written in Go
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
792 B

  1. package pipelines
  2. import (
  3. "github.com/disintegration/imaging"
  4. "image"
  5. )
  6. type IExecutableStep interface {
  7. Execute(src image.Image) (image.Image, error)
  8. }
  9. // Resize image
  10. type ResizeImageStep struct {
  11. Step
  12. Options struct {
  13. Width int `json:"width"`
  14. Height int `json:"height"`
  15. Upscale bool `json:"upscale"`
  16. } `json:"options"`
  17. }
  18. func (s ResizeImageStep) Execute(src image.Image) (image.Image, error) {
  19. src = imaging.Resize(src, s.Options.Width, s.Options.Height, imaging.Linear)
  20. return src, nil
  21. }
  22. // Rotate image
  23. type RotateImageStep struct {
  24. Step
  25. Options struct {
  26. Angle float64 `json:"angle"`
  27. } `json:"options"`
  28. }
  29. func (s RotateImageStep) Execute(src image.Image) (image.Image, error) {
  30. src = imaging.Rotate(src, s.Options.Angle, image.Black)
  31. return src, nil
  32. }