The height and width properties of an image element (like the offsetHeight and offsetWidth properties of any element),
return 0 instead of the actual values until it has been added to some document (and if its style.display attribute is not set to "none").
A common way to work around this is displaying the image outside the visible area of your page; your users will not see it, and its height and width properties will return the actual values instead of 0.
Then you should remove the image from the document.

If you check this link here is a method to get all the image dimensions in a directory with PHP which checks it without having to load it to the page. This might help you. You can pass it to your js with a