Skip to content

Instantly share code, notes, and snippets.

@brschwar
Created January 19, 2016 14:52
Show Gist options
  • Save brschwar/0e7887048996cd7074e7 to your computer and use it in GitHub Desktop.
Save brschwar/0e7887048996cd7074e7 to your computer and use it in GitHub Desktop.
JavaScript to replace images with placeholders and display their height and width in a div layered on top.
(function(){
jQuery("img").each(function() {
var h, w, x, y, m, i;
h = this.height;
w = this.width;
l = Math.ceil(jQuery(this).offset().left) + 5;
t = Math.ceil(jQuery(this).offset().top);
jQuery('section').css('position', 'relative');
m = "Image Size: " + w + "x" + h;
i = "http://placehold.it/" + w + "x" + h;
jQuery('<div><p>'+ m +'</p></div>').css({
"position" : "absolute",
"left" : l,
"top" : t,
"zIndex" : 1000
}).appendTo(jQuery('body'));
jQuery(this).attr('src', i);
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment