Page 1 of 1

Images from the Web

Posted: Wed Apr 20, 2016 6:22 pm
by MicroMacro
Is it possible, using something like lua socket or something like that, to get and use images from the web in a love project?
Thanks!

Re: Images from the Web

Posted: Wed Apr 20, 2016 6:33 pm
by unek
MicroMacro wrote:Is it possible, using something like lua socket or something like that, to get and use images from the web in a love project?
Thanks!
Yes. You can use luasocket's http.request and love.image.newImageData to do so.

Re: Images from the Web

Posted: Wed Apr 20, 2016 7:01 pm
by MicroMacro
Could you provide an example?

Re: Images from the Web

Posted: Wed Apr 20, 2016 7:31 pm
by bartbes

Code: Select all

local http = require "socket.http"

local logo

function love.load()
	logo = http.request("http://love2d.org/style/logo.png")
	logo = love.filesystem.newFileData(logo, "logo.png")
	logo = love.graphics.newImage(logo)
end

function love.draw()
	love.graphics.draw(logo)
end
Of course you'd probably want to deal with errors, but, if there are none, this code will draw the love logo.