Spaces:
Running
Running
File size: 429 Bytes
16c06bf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
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))
|