I want to display an image file from a local folder in JavaScript (p5.js). Every time I try I get: Access to image at "XXXXX" from origin "null" has been block by CORS policy: The response is invalid.
The HTML, js and images are all inside a file tree, inside the media server's project folder.
They HAVE to be run locally. Running from any other location than the folder they are in is not an option (referring to a lot of answers talking about running a web server.
function setup() {
createCanvas(96, 192);
img = loadImage('images/square1-01.png'); // Load the image
}
function draw() {
image(img, 0, 0);
}
//ALSO TRIED
img = loadImage('file://images/square1-01.png'); // Load the image
The above text is a super simplified version that I isolated from the main file so I could run it standalone, just so I could get to the point of getting an image, before I started adding in the other layers of complexity. Thus the layout is entirely from a tutorial.
Relevant files are:
.../web/d3test.html
.../web/d3test.js
.../web/images/square1-01
.../web/images/square2-01
.../web/images/square3-01