rotate_and_flip.go 598 B

1234567891011121314151617181920212223242526272829
  1. package processing
  2. import (
  3. "github.com/imgproxy/imgproxy/v3/imagedata"
  4. "github.com/imgproxy/imgproxy/v3/options"
  5. "github.com/imgproxy/imgproxy/v3/vips"
  6. )
  7. func rotateAndFlip(pctx *pipelineContext, img *vips.Image, po *options.ProcessingOptions, imgdata *imagedata.ImageData) error {
  8. if pctx.angle%360 == 0 && po.Rotate%360 == 0 && !pctx.flip {
  9. return nil
  10. }
  11. if err := img.CopyMemory(); err != nil {
  12. return err
  13. }
  14. if err := img.Rotate(pctx.angle); err != nil {
  15. return err
  16. }
  17. if pctx.flip {
  18. if err := img.Flip(); err != nil {
  19. return err
  20. }
  21. }
  22. return img.Rotate(po.Rotate)
  23. }