Say train of thought only, in order to offer reference!
Create an img dynamically, insert the url of the largest image, and set the display state to no or width to 0.
When the onload event ends, you can tell that the image resource is loaded.
Then remove the IMG