P5.js: loadImage() won't load image

Created on 13 Sep 2015  路  2Comments  路  Source: processing/p5.js

var image = loadImage("portrait.jpg");
image = loadImage("/Users/richard/Documents/Code/portrait.jpg");
image = loadImage("http://stanford.edu/about/images/intro_about.jpg");

I checked to make sure the image and the .js file are in the same directory. All three methods return the same Javascript error to the console:

p5.js says: It looks like there was a problem loading your image. Try checking if the file path [...insert file path here...] is correct, hosting the image online, or running a local server.[https://github.com/processing/p5.js/wiki/Local-server]

Most helpful comment

Fixed the issue. Browser security blocked the file path, so I needed to run a local server.

All 2 comments

hi @rchen8 only the first one will work, the path needs to be relative to the HTML file. loading from any other location doesn't work as the browser may prevent it due to security issues. I just tested line one and it seems to work for me.

Fixed the issue. Browser security blocked the file path, so I needed to run a local server.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bassamanator picture bassamanator  路  3Comments

kartikay-bagla picture kartikay-bagla  路  3Comments

kappaxbeta picture kappaxbeta  路  3Comments

b0nb0n picture b0nb0n  路  3Comments

aparrish picture aparrish  路  3Comments