import cv2
import numpy as np


def validate_image(image_bytes: bytes):

    nparr = np.frombuffer(
        image_bytes,
        np.uint8
    )

    image = cv2.imdecode(
        nparr,
        cv2.IMREAD_COLOR
    )

    if image is None:
        raise Exception(
            "Invalid image."
        )

    return image