P5.js: loadImage() not working

Created on 8 Jan 2017  路  3Comments  路  Source: processing/p5.js

When I use bg = loadImage("data/Myimage.jpg"); or bg = loadImage('data/Myimage.jpg'); or bg = loadImage("Myimage.jpg"); or bg = loadImage('Myimage.jpg'); it says " file:///C: ..... from origin 'null' has been blocked by CORS policy: Invalid response. Origin 'null' is therefore not allowed access."

I have tried using bg = createImg('Myimage.jpg'), (createImage doesnt work ...) and it works, but then I can't use background(bg); , it says "Uncaught Error: [object Arguments]is not a valid color representation.".
I also tried background(bg,10); and background(bg,100); it doesnt give any error on the console, but it doesnt show any image.

Most helpful comment

Here is a place in the wiki on setting up a local server: https://github.com/processing/p5.js/wiki/Local-server

All 3 comments

is the image file within a folder called date within your project folder? the page specified in loadImage() should be relative to your html file.

Are you working on a server? CORS is usually blocked on local files.

Here is a place in the wiki on setting up a local server: https://github.com/processing/p5.js/wiki/Local-server

Was this page helpful?
0 / 5 - 0 ratings

Related issues

oranyelik picture oranyelik  路  3Comments

Vbbab picture Vbbab  路  3Comments

sps014 picture sps014  路  3Comments

stalgiag picture stalgiag  路  3Comments

bassamanator picture bassamanator  路  3Comments