added image ai-moderation
This commit is contained in:
39
ai-moderation/app/moderation/image/validator.py
Normal file
39
ai-moderation/app/moderation/image/validator.py
Normal file
@@ -0,0 +1,39 @@
|
||||
from PIL import Image
|
||||
|
||||
from app.exceptions.invalid_image_exception import InvalidImageException
|
||||
|
||||
|
||||
class ImageValidator:
|
||||
|
||||
MIN_WIDTH = 50
|
||||
MIN_HEIGHT = 50
|
||||
|
||||
MAX_WIDTH = 10000
|
||||
MAX_HEIGHT = 10000
|
||||
|
||||
def validate(
|
||||
self,
|
||||
image: Image.Image
|
||||
) -> None:
|
||||
|
||||
width, height = image.size
|
||||
|
||||
if width < self.MIN_WIDTH:
|
||||
raise InvalidImageException(
|
||||
f"Image width is too small: {width}"
|
||||
)
|
||||
|
||||
if height < self.MIN_HEIGHT:
|
||||
raise InvalidImageException(
|
||||
f"Image height is too small: {height}"
|
||||
)
|
||||
|
||||
if width > self.MAX_WIDTH:
|
||||
raise InvalidImageException(
|
||||
f"Image width is too large: {width}"
|
||||
)
|
||||
|
||||
if height > self.MAX_HEIGHT:
|
||||
raise InvalidImageException(
|
||||
f"Image height is too large: {height}"
|
||||
)
|
||||
Reference in New Issue
Block a user