You can use the onload
event handler, no need for Promise.
The code below loads an image, after load has finished it shows the size, and 2 seconds after that it resizes the image. The delay is just for demo purposes, so you can see the image being resized. Normally you'd use image.onload = SetDimensions;
.
var image = $("#img")[0];
image.onload = ShowThenSetDimensions;
image.src = "https://www.gravatar.com/avatar/0a88079f9234aca9f67c04bf7b94eca4?s=32&d=identicon&r=PG&f=1";
function ShowThenSetDimensions() {
console.log("Size: " + image.naturalWidth + " x " + image.naturalHeight);
console.log("SetDimensions will be called in 2 seconds");
window.setTimeout(SetDimensions, 2000);
}
function SetDimensions() {
image.style.width = image.naturalWidth + "px";
image.style.height = image.naturalHeight + "px";
console.log("SetDimensions done");
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<img id="img" style="width:10px; height:10px">