How to load image from cross-site

Get help using Construct 2

Post » Fri Jul 13, 2012 11:38 am

I know the official action:load image from URL could not load image from cross-site.
Is there any way (in javascript code) or any library to load image from cross-site? I have no idea after asking google. rexrainbow2012-07-13 11:39:05
B
97
S
22
G
178
Posts: 4,121
Reputation: 104,049

Post » Fri Jul 13, 2012 12:13 pm

Ive done a fast search about this and founded this: Ajax cross domain.

I havent had time to read it, but maybe it can help you, no idea :).
B
14
S
4
G
3
Posts: 106
Reputation: 4,792

Post » Fri Jul 13, 2012 12:18 pm

@sirLobito

Thanks, I use this library for cross-domain ajax (ajax.get) -- Cross-domain requests with jQuery, it works. But I don't know how to use it for image.
B
97
S
22
G
178
Posts: 4,121
Reputation: 104,049

Post » Fri Jul 13, 2012 12:22 pm

What you want is to send xxx data via Ajax and receive and image for example?

And cant you send back not an image, instead, its source, and use that string as imgs src?
B
14
S
4
G
3
Posts: 106
Reputation: 4,792

Post » Sat Jul 14, 2012 1:29 am

@sirLobito

I had a plugin request to get and parse html file and get image from other web site (cross-domain).
B
97
S
22
G
178
Posts: 4,121
Reputation: 104,049

Post » Sat Jul 14, 2012 3:54 pm

The target image must be sent with the Access-Control-Allow-Origin: * HTTP header. It's described in the AJAX manual entry. If the image is not sent with that header, there's not much you can do, it's the equivalent of the server saying "you are not allowed to use this image".
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Sat Jul 14, 2012 4:55 pm

There's a trick : you need to display the image in a classic <img> tag.
When it's done, that image can be pasted on a <canvas>, in a 'classic' way.
You can then do a .toDataURL() from the <canvas>, to have the base64 string representation of that image.
With that image string, you can then do what you want .
B
33
S
9
G
6
Posts: 709
Reputation: 6,704

Post » Sun Jul 15, 2012 3:30 am

@Ashley
@Pode

Thanks. I'll try it.
B
97
S
22
G
178
Posts: 4,121
Reputation: 104,049

Post » Sun Jul 15, 2012 9:07 am

@Pode

I use your div plugin, put <img> tag by action:innerhtml. It works, thanks.
B
97
S
22
G
178
Posts: 4,121
Reputation: 104,049

Post » Sun Jul 15, 2012 7:25 pm

@rexrainbow : you're welcome ;).
B
33
S
9
G
6
Posts: 709
Reputation: 6,704

Next

Return to How do I....?

Who is online

Users browsing this forum: PixelatedTrip, Yahoo [Bot] and 0 guests