request_image()

Use a Py5Promise object to load an image into a variable of type Py5Image.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
def draw():
    global img_promise
    if py5.frame_count == 1:
        # the request should only be made once
        img_promise = py5.request_image('http://py5.ixora.io/images/examples/apples.jpg')

    py5.background(0)
    if img_promise.is_ready:
        py5.image(img_promise.result, 10, 10)
    else:
        py5.println('not ready')

Description

Use a Py5Promise object to load an image into a variable of type Py5Image. This method provides a convenient alternative to combining launch_promise_thread() with load_image() to load image data.

Consider using request_image() to load image data from within a Sketch’s draw() function. Using load_image() in the draw() function would slow down the Sketch animation.

The returned Py5Promise object has an is_ready property that will be True when the result property contains the value function f returned. Before then, the result property will be None.

Syntax

request_image(image_path: Union[str, Path]) -> Py5Promise

Parameters

  • image_path: Union[str, Path] - url or file path for image file

Updated on September 11, 2021 16:51:34pm UTC