image_size.go 760 B

1234567891011121314151617181920212223242526
  1. package security
  2. import (
  3. "github.com/imgproxy/imgproxy/v3/config"
  4. "github.com/imgproxy/imgproxy/v3/ierrors"
  5. "github.com/imgproxy/imgproxy/v3/imath"
  6. )
  7. var ErrSourceResolutionTooBig = ierrors.New(422, "Source image resolution is too big", "Invalid source image")
  8. var ErrSourceFrameResolutionTooBig = ierrors.New(422, "Source image frame resolution is too big", "Invalid source image")
  9. func CheckDimensions(width, height, frames int) error {
  10. frames = imath.Max(frames, 1)
  11. if frames > 1 && config.MaxAnimationFrameResolution > 0 {
  12. if width*height > config.MaxAnimationFrameResolution {
  13. return ErrSourceFrameResolutionTooBig
  14. }
  15. } else {
  16. if width*height*frames > config.MaxSrcResolution {
  17. return ErrSourceResolutionTooBig
  18. }
  19. }
  20. return nil
  21. }