Warning

This document is for an in-development version of Galaxy. You can alternatively view this page in the latest release if it exists or view the top of the latest release's documentation.

Source code for galaxy.util.image_util

"""Provides utilities for working with image files."""

import logging
from typing import (
    List,
    Optional,
)

try:
    from PIL import Image
except ImportError:
    Image = None  # type: ignore[assignment, unused-ignore]

log = logging.getLogger(__name__)


[docs]def image_type(filename: str) -> Optional[str]: fmt = None if Image is not None: try: with Image.open(filename) as im: fmt = im.format except Exception: pass if fmt: return fmt.upper() else: return None
[docs]def check_image_type(filename: str, types: List[str]) -> bool: fmt = image_type(filename) if fmt in types: return True return False