from django.core.exceptions import ValidationError
from PIL import Image

def validate_image(file):
    """Ensure uploaded file is a valid image format."""
    try:
        img = Image.open(file)
        img.verify()
    except Exception:
        raise ValidationError("Invalid image file. Please upload a valid image.")
