Is it possible to make a Clarification:
Ok, my solution is a little bit tricky, but it works. It's a javascript and involve jquery as you wanted. The idea is to create a new image, add it to the DOM, waits till it loads and gets its dimensions. After that the new image is removed and the width and height are applied to the original img tag. Here is a js fiddle demonstrating the workaround http://jsfiddle.net/krasimir/bH5JZ/5/
And here is the code:
$(document).ready(function() {
var image = $("#image");
var imageurl = image.css("background-image").replace(/url/, '').replace(/\(/, '').replace(/\)/, '');
var body = $("body");
var newimage = $('
');
newimage.css("display", "none");
body.append(newimage);
newimage.on("load", function() {
var w = $(this).width();
var h = $(this).height();
image.css("width", w);
image.css("height", h);
newimage.remove();
});
});
And the css:
#image {
margin: 0px auto;
background-image:url('http://www.w3.org/html/logo/downloads/HTML5_Logo_512.png');
background-repeat:no-repeat;
background-size:100%;
background-color:yellow;
}