image_size.go 690 B

1234567891011121314151617181920212223242526
  1. package security
  2. import (
  3. "github.com/imgproxy/imgproxy/v3/imagemeta"
  4. "github.com/imgproxy/imgproxy/v3/imath"
  5. )
  6. func CheckDimensions(width, height, frames int, opts Options) error {
  7. frames = imath.Max(frames, 1)
  8. if frames > 1 && opts.MaxAnimationFrameResolution > 0 {
  9. if width*height > opts.MaxAnimationFrameResolution {
  10. return newImageResolutionError("Source image frame resolution is too big")
  11. }
  12. } else {
  13. if width*height*frames > opts.MaxSrcResolution {
  14. return newImageResolutionError("Source image resolution is too big")
  15. }
  16. }
  17. return nil
  18. }
  19. func CheckMeta(meta imagemeta.Meta, opts Options) error {
  20. return CheckDimensions(meta.Width(), meta.Height(), 1, opts)
  21. }