The loadImage() function is used to load an image from the given path and create a p5.Image object with the image.
It is advised to load an image in the preload() function as the loaded image may not be available for use immediately. The image is preferably loaded from a relative path as some browsers may prevent loading from other remote locations due to the browser’s security features.
loadImage(path, successCallback, failureCallback)
Parameters: This function accepts three parameter as mentioned above and described below.
- path: This is the path from where the image is to be loaded.
- successCallback: This is a function which is called if the image successfully loads and it is an optional parameter.
- failureCallback: This is a function which is called if the image does not load due to any error and it is an optional parameter.
Below examples illustrates the loadImage() function in p5.js:
Example 1: This example shows the loading of image in preload().
Example 2: This example shows loading an image from a URL and both callbacks that may take place.
- Image successfully loads
- Image does not load
Online editor: https://editor.p5js.org/
Environment Setup: https://www.geeksforgeeks.org/p5-js-soundfile-object-installation-and-methods/
- How to get the function name inside a function in PHP ?
- PHP | imagecreatetruecolor() Function
- p5.js | year() function
- D3.js | d3.utcTuesdays() Function
- PHP | ImagickDraw getTextAlignment() Function
- PHP | Ds\Sequence last() Function
- Function to escape regex patterns before applied in PHP
- PHP | array_udiff_uassoc() Function
- PHP | geoip_continent_code_by_name() Function
- D3.js | d3.map.set() Function
- D3.js easePolyOut Function
- PHP | GmagickPixel setcolor() function
- PHP | opendir() Function
- PHP | cal_to_jd() Function
- D3.js | d3.bisectLeft() Function
- PHP | stream_get_transports() Function
- PHP | Ds\Deque pop() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.