Import picture from any url

hello ,

i’m using import picture like that :
const advancedTextureImage = GUI.AdvancedDynamicTexture.CreateForMesh(plane);
const image = new GUI.Image(’ ', ‘./assets/images/’ +;

the probleme is i want to use a dynamic Url (from any path) to accept any picture from any folder .

thanks for help

A URL is a URL, whether local or from a different domain. You need to make sure that the domain accepts CORS (otherwise the request will fail), but other then that it doesn’t matter what URL you are entering.


Hi @RaananW, good to see you, hope you are well. I brought a Gui 2d imageControl demo home (zip DL) and tried… file:///sameDirAsIndexHtml/img.png - no joy. Maybe need some localHost url… or maybe need a local web server? And ideas about those things? thx.

./img.png didn’t work, but that’s not a url, as you pointed out.

localhost? port 8080? Local images need to come from locally-running webserver? 2-slash? 3-slash?

Sorry if I’m causing trouble. I am also reading about this stuff… as fast/hard as possible. I don’t mean to be a pain, but I/we/others might need more answer details, perhaps. thx! (all commenters welcome, of course.)

1 Like

@Wingnut, ./img.png is a url. It is a url path relative to the html file location.

@Viche, if you mean you wish to relative path to folders higher than dot, e.g. ../../../../image.png, web servers are going to block you trying to read anything above. That would a major security problem.

On a sightly different tac, I run all my scenes during development, some being very large tools with also read files, from file://mypage.html. It avoids a local web server, which is just another point of failure, & caching might mean you are not seeing the latest files.

Chrome does not allow reading anything but other JS files with a file:// html file. Edge does, but you cannot use microphones. My preferred is Firefox, but they recently are blocking too. To unblock on Firefox just:

change privacy.file_unique_origin to False in about:config


Thx JC… that made ./img.png in Firefox… work for me.

var image = new BABYLON.GUI.Image("but", "./img.png");

And thx for the url/not-url correction, too. Hope you’re well. Viche, are you rolling? Hope so.

Viche… CORS can get in the way of your any url idea (as RaananW mentioned)… so… here’s what I do… sometimes…

That is a tinyUrl version of a Google IMAGE search for cow and wikimedia (at same time) with TOOLS tab set-to “Labeled For ReUse”. Generally, all wikimedia images are CORS-clear (and I hear Facebook images are, as well, and surely some others).

Let’s try that first cow-pie… err… I mean cow-pic. Into the playground we go (the playground needs CORS-cleared images, too)

As Jami Gertz stated… in the movie Twister… “We got cows:slight_smile:

Change the word cow to ANY other search term… and you should be returned a pile of CORS-clear (Labeled for ReUse) images.

1 Like

thanks a lot @JCPalmer, @Wingnut and @RaananW for the solution :slight_smile: