image_size.go 726 B

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