Load a sprite from URL

Just starting out? Need help? Post your questions and find answers here.
itzybitzyspider
Posts: 27
Joined: Tue Nov 22, 2022 4:36 am

Load a sprite from URL

Post by itzybitzyspider »

Hello,

Is there a way to load a sprite image from a URL?

So trying to load dynamically from a list of URLs I get from an API call.

Thanks
User avatar
Paul
Posts: 195
Joined: Wed Feb 26, 2014 6:46 pm
Location: Canada
Contact:

Re: Load a sprite from URL

Post by Paul »

You will not be able to load an image from another website.
Your Browser will block it for security reasons.

Images must exist on the same server/location as your app.

Maybe read this thread for better explanation...
viewtopic.php?t=2265
itzybitzyspider
Posts: 27
Joined: Tue Nov 22, 2022 4:36 am

Re: Load a sprite from URL

Post by itzybitzyspider »

Hello, so I'm looking at getting from HTTP the image itself. Since I got the response, can I pass it / encode / decode it into a format which I can LoadSprite into? Or worse case I guess I can put a script at the source URL (server) to convert the image into base64 and then I can read it into LoadSprite. However, I'd like to have it all in Spider and not have to maintain another script somewhere. There was a Base64Encoder function in PB but not in SB...

Code: Select all

Procedure HttpGetEvent(Success, Result$, UserData)
    If Success
      Debug Result$
    Else
      Debug "HTTPRequest(): Error"
    EndIf
  EndProcedure
  
  ; Get the content of this file, and display it in the debug window
  ;
  HTTPRequest(#PB_HTTP_Get, "https://xxx.ngrok.io/static/test.jpg", "", @HttpGetEvent())
User avatar
useful
Posts: 116
Joined: Tue Feb 25, 2014 1:15 pm

Re: Load a sprite from URL

Post by useful »

2B or not 2B = FF
itzybitzyspider
Posts: 27
Joined: Tue Nov 22, 2022 4:36 am

Re: Load a sprite from URL

Post by itzybitzyspider »

I'm posting this so next time we're all good.

If you have control over your http server (in this case I have), with an Apache for example. You add it in your config or the .htaccess file. Look at the security risks before doing this. I don't have an issue because it's public images anyways.

Code: Select all

<VirtualHost *:443>
   ...
   Header add Access-Control-Allow-Origin "*"
   ...
</VirtualHost>
This will allow your app to just do this directly.

Code: Select all

LoadSprite(0,  "https://xxx.xxx-xx.com/xx/xx-xxx.jpg")
Or you have to have an in-between proxy of some sort which will allow * origin and then get the file for you. Squid proxy or Nginx would do.
Post Reply