How to find width and height of a URL loaded image?

I followed this link and displayed a URL image on-screen.
https://docs.coronalabs.com/api/library/display/loadRemoteImage.html
but how do I get the width and height of the URL loaded image?
.width and .height doesn’t seem to work

Quoting docs:

Nothing is returned from calling this function. The listener callback will contain the display object value ( event.target ) if the download was successful.

local function remoteImageListener(event)
	if (event.target) then
		print (event.target, event.target.width, event.target.height)
	end
end


display.loadRemoteImage( "https://solar2d.com/images/logo-banner.png", "GET", remoteImageListener, "solar2d" )
1 Like

@joshjarc - nice work @bgmadclown - I think there two important things to consider here…

  1. you’ll want to include an x and y parameter, otherwise it will display at 0,0 on-screen the moment the load finishes; i recommend putting it off-screen so you can then display it the size you want, retain the proportions and place it where you want.
  2. i often use “local ratio = event.target.height / event.target.width” so that I can keep the proportions right no matter where I want to put it. Just set the x,y and width what you want it to be, then use the width*ratio to get the proper height.

With these two things, you can load off-screen and then position it exactly where you want it and what size quite easily. Good luck!

3 Likes