MCPcopy Create free account
hub / github.com/YesianRohn/TextSSR / load_image

Function load_image

diffusers/src/diffusers/utils/testing_utils.py:467–495  ·  view source on GitHub ↗

Loads `image` to a PIL Image. Args: image (`str` or `PIL.Image.Image`): The image to convert to the PIL Image format. Returns: `PIL.Image.Image`: A PIL Image.

(image: Union[str, PIL.Image.Image])

Source from the content-addressed store, hash-verified

465
466
467def load_image(image: Union[str, PIL.Image.Image]) -> PIL.Image.Image:
468 """
469 Loads `image` to a PIL Image.
470
471 Args:
472 image (`str` or `PIL.Image.Image`):
473 The image to convert to the PIL Image format.
474 Returns:
475 `PIL.Image.Image`:
476 A PIL Image.
477 """
478 if isinstance(image, str):
479 if image.startswith("http://") or image.startswith("https://"):
480 image = PIL.Image.open(requests.get(image, stream=True).raw)
481 elif os.path.isfile(image):
482 image = PIL.Image.open(image)
483 else:
484 raise ValueError(
485 f"Incorrect path or url, URLs must start with `http://` or `https://`, and {image} is not a valid path"
486 )
487 elif isinstance(image, PIL.Image.Image):
488 image = image
489 else:
490 raise ValueError(
491 "Incorrect format used for image. Should be an url linking to an image, a local path, or a PIL image."
492 )
493 image = PIL.ImageOps.exif_transpose(image)
494 image = image.convert("RGB")
495 return image
496
497
498def preprocess_image(image: PIL.Image, batch_size: int):

Calls

no outgoing calls

Tested by

no test coverage detected