Spaces:
Running
Running
from typing import Any | |
import click | |
from PIL import Image | |
class ImageParamType(click.ParamType): | |
name = "image" | |
def convert( | |
self, value: Any, param: click.Parameter | None, ctx: click.Context | None | |
) -> Any: | |
if value is None or isinstance(value, Image.Image): | |
return value | |
try: | |
return Image.open(value) | |
except OSError as e: | |
self.fail(str(e)) | |