MCPcopy Create free account
hub / github.com/TencentARC/BrushNet / load_image

Function load_image

src/diffusers/utils/loading_utils.py:9–49  ·  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. convert_method (Callable[[PIL.Image.Image], PIL.Image.Image], optional): A conversion method to apply to the image after loading it.

(
    image: Union[str, PIL.Image.Image], convert_method: Callable[[PIL.Image.Image], PIL.Image.Image] = None
)

Source from the content-addressed store, hash-verified

7
8
9def load_image(
10 image: Union[str, PIL.Image.Image], convert_method: Callable[[PIL.Image.Image], PIL.Image.Image] = None
11) -> PIL.Image.Image:
12 """
13 Loads `image` to a PIL Image.
14
15 Args:
16 image (`str` or `PIL.Image.Image`):
17 The image to convert to the PIL Image format.
18 convert_method (Callable[[PIL.Image.Image], PIL.Image.Image], optional):
19 A conversion method to apply to the image after loading it.
20 When set to `None` the image will be converted "RGB".
21
22 Returns:
23 `PIL.Image.Image`:
24 A PIL Image.
25 """
26 if isinstance(image, str):
27 if image.startswith("http://") or image.startswith("https://"):
28 image = PIL.Image.open(requests.get(image, stream=True).raw)
29 elif os.path.isfile(image):
30 image = PIL.Image.open(image)
31 else:
32 raise ValueError(
33 f"Incorrect path or URL. URLs must start with `http://` or `https://`, and {image} is not a valid path."
34 )
35 elif isinstance(image, PIL.Image.Image):
36 image = image
37 else:
38 raise ValueError(
39 "Incorrect format used for the image. Should be a URL linking to an image, a local path, or a PIL image."
40 )
41
42 image = PIL.ImageOps.exif_transpose(image)
43
44 if convert_method is not None:
45 image = convert_method(image)
46 else:
47 image = image.convert("RGB")
48
49 return image

Callers 15

get_dummy_inputsMethod · 0.90
test_i2vgen_xlMethod · 0.90
test_sd_videoMethod · 0.90
test_amused_256Method · 0.90
test_amused_256_fp16Method · 0.90
test_amused_512Method · 0.90
test_amused_512_fp16Method · 0.90
test_amused_256Method · 0.90
test_amused_256_fp16Method · 0.90

Calls

no outgoing calls

Tested by 15

get_dummy_inputsMethod · 0.72
test_i2vgen_xlMethod · 0.72
test_sd_videoMethod · 0.72
test_amused_256Method · 0.72
test_amused_256_fp16Method · 0.72
test_amused_512Method · 0.72
test_amused_512_fp16Method · 0.72
test_amused_256Method · 0.72
test_amused_256_fp16Method · 0.72