Yingrjimsch
Yingrjimsch

Reputation: 122

Load all images of directory p5.js

I'm new into p5.js and achieved to play around with loading images. Now I want to load a bunch of images which are in the same folder. Is it possible to load these in a loop or somehow I don't have to know their names?

Thank you very much for your suggestions. Yingrjimsch

Upvotes: 0

Views: 1625

Answers (1)

Kevin Workman
Kevin Workman

Reputation: 42176

First I think you need to be a little more specific about where the images are:

  • Are they on the user's hard drive?
  • Are they on the web somewhere?

Depending on the answer to those questions, you can then google for a more specific solution. Googling "JavaScript load directory of images" will return a ton of results.

If you're talking about loading a directory of images from the web, which approach you take might also depend on the behavior of your web server that's hosting the files. For example some file servers will automatically create an index.html file inside every directory that just lists the other files in that directory. If that's the case, then you can just parse that link to get the URLs of the images in the directory. If not, you might have to create that file yourself.

There are probably other approaches, but that's how I'd do it.

Upvotes: 0

Related Questions