MCPcopy
hub / github.com/processing/p5.js / loadingDisplaying

Function loadingDisplaying

src/image/loading_displaying.js:13–1406  ·  view source on GitHub ↗
(p5, fn)

Source from the content-addressed store, hash-verified

11import { GIFEncoder, quantize, nearestColorIndex } from 'gifenc';
12
13function loadingDisplaying(p5, fn){
14 /**
15 * Loads an image to create a <a href="#/p5.Image">p5.Image</a> object.
16 *
17 * `loadImage()` interprets the first parameter one of three ways. If the path
18 * to an image file is provided, `loadImage()` will load it. Paths to local
19 * files should be relative, such as `'assets/thundercat.jpg'`. URLs such as
20 * `'https://example.com/thundercat.jpg'` may be blocked due to browser
21 * security. Raw image data can also be passed as a base64 encoded image in
22 * the form `'data:image/png;base64,arandomsequenceofcharacters'`. The `path`
23 * parameter can also be defined as a [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request)
24 * object for more advanced usage.
25 *
26 * The second parameter is optional. If a function is passed, it will be
27 * called once the image has loaded. The callback function can optionally use
28 * the new <a href="#/p5.Image">p5.Image</a> object. The return value of the
29 * function will be used as the final return value of `loadImage()`.
30 *
31 * The third parameter is also optional. If a function is passed, it will be
32 * called if the image fails to load. The callback function can optionally use
33 * the event error. The return value of the function will be used as the final
34 * return value of `loadImage()`.
35 *
36 * This function returns a `Promise` and should be used in an `async` setup with
37 * `await`. See the examples for the usage syntax.
38 *
39 * @method loadImage
40 * @param {String|Request} path path of the image to be loaded or base64 encoded image.
41 * @param {function(p5.Image)} [successCallback] function called with
42 * <a href="#/p5.Image">p5.Image</a> once it
43 * loads.
44 * @param {function(Event)} [failureCallback] function called with event
45 * error if the image fails to load.
46 * @return {Promise<p5.Image>} the <a href="#/p5.Image">p5.Image</a> object.
47 *
48 * @example
49 * let img;
50 *
51 * // Load the image and create a p5.Image object.
52 * async function setup() {
53 * img = await loadImage('assets/laDefense.jpg');
54 * createCanvas(100, 100);
55 *
56 * // Draw the image.
57 * image(img, 0, 0);
58 *
59 * describe('Image of the underside of a white umbrella and a gridded ceiling.');
60 * }
61 *
62 * @example
63 * async function setup() {
64 * // Call handleImage() once the image loads.
65 * await loadImage('assets/laDefense.jpg', handleImage);
66 *
67 * describe('Image of the underside of a white umbrella and a gridded ceiling.');
68 * }
69 *
70 * // Display the image.

Callers 3

loading.jsFile · 0.85
graphicsFunction · 0.85

Calls 15

requestFunction · 0.90
_createGifFunction · 0.85
_flipPixelsFunction · 0.85
_generateGlobalPaletteFunction · 0.85
getIndexedFrameFunction · 0.85
_sAssignFunction · 0.85
_imageFitFunction · 0.85
idMethod · 0.80
styleMethod · 0.80
positionMethod · 0.80
noLoopMethod · 0.80
htmlMethod · 0.80

Tested by

no test coverage detected