schon/core/validators.py
2025-10-06 15:58:30 +03:00

14 lines
526 B
Python

from django.core.exceptions import ValidationError
from django.core.files.images import ImageFile, get_image_dimensions
from django.utils.translation import gettext_lazy as _
def validate_category_image_dimensions(image: ImageFile) -> None:
max_width = 99999
max_height = 99999
if image:
width, height = get_image_dimensions(image.file)
if width > max_width or height > max_height:
raise ValidationError(_(f"image dimensions should not exceed w{max_width} x h{max_height} pixels"))