In my particular case, I needed something which would work with background-image: linear-gradient(rgba(0, 0, 0, 0.4),rgba(0, 0, 0, 0.4)), url(...)
. I needed also a code that would be able to check several image from a specific class without copying the code for each image.
Maybe it could be useful for someone !
(I'm absolutely not an Jquery expert, since I started to code a month ago for my personal website.. So feel free to correct if needed !)
This work latest jQuery 3 and IE11 too. for backward JQuery compatibility, I think you can only replace .on("load", function()
by .load(function()
.
//will check all div with this class or id
var $image = $('#myDiv');
//will extract url only by splitting property on comas (takes care of comas on rgba(x, x, x, x))
var imageUrl = $image.css('background-image').split(",")[8].replace('url(','').replace(')','').replace('"','').replace('"','');
var img = new Image ;
img.src = imageUrl;
$(img).on("load", function() {
var image_width = img.width;
var image_height = img.height;
console.log(image_width + " x " + image_height) ;
}) ;