Skip to content

Instantly share code, notes, and snippets.

@pH200
Created November 16, 2014 09:17
Show Gist options
  • Save pH200/21a78e99408a650062c5 to your computer and use it in GitHub Desktop.
Save pH200/21a78e99408a650062c5 to your computer and use it in GitHub Desktop.
Image size getter
function imageSizeGetter(image: HTMLImageElement, callback: (size:[number, number]) => any): void {
if (image.width > 0 && image.height > 0) {
callback([image.width, image.height]);
} else {
var observer = new MutationObserver(function (record) {
observer.disconnect();
callback([image.width, image.height]);
});
observer.observe(image, {
attributes: true,
attributeFilter: ["width", "height"]
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment