MCPcopy
hub / github.com/huggingface/diffusers / load_image

Function load_image

src/diffusers/utils/testing_utils.py:715–743  ·  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: str | PIL.Image.Image)

Source from the content-addressed store, hash-verified

713
714
715def load_image(image: str | PIL.Image.Image) -> PIL.Image.Image:
716 """
717 Loads `image` to a PIL Image.
718
719 Args:
720 image (`str` or `PIL.Image.Image`):
721 The image to convert to the PIL Image format.
722 Returns:
723 `PIL.Image.Image`:
724 A PIL Image.
725 """
726 if isinstance(image, str):
727 if image.startswith("http://") or image.startswith("https://"):
728 image = PIL.Image.open(requests.get(image, stream=True, timeout=DIFFUSERS_REQUEST_TIMEOUT).raw)
729 elif os.path.isfile(image):
730 image = PIL.Image.open(image)
731 else:
732 raise ValueError(
733 f"Incorrect path or url, URLs must start with `http://` or `https://`, and {image} is not a valid path"
734 )
735 elif isinstance(image, PIL.Image.Image):
736 image = image
737 else:
738 raise ValueError(
739 "Incorrect format used for image. Should be an url linking to an image, a local path, or a PIL image."
740 )
741 image = PIL.ImageOps.exif_transpose(image)
742 image = image.convert("RGB")
743 return image
744
745
746def preprocess_image(image: PIL.Image, batch_size: int):

Callers

nothing calls this directly

Calls 1

getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…