Skip to content

Instantly share code, notes, and snippets.

@falsefalse
Created June 15, 2010 18:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save falsefalse/439444 to your computer and use it in GitHub Desktop.
Save falsefalse/439444 to your computer and use it in GitHub Desktop.
afair, this prints dimensions for all background images on the page
console.clear && console.clear();
var images = [];
var elements = document.querySelectorAll('#global div');
for (var i = 0, l = elements.length; i < l; i++) {
var element = elements[i];
var bgImg = document.defaultView.getComputedStyle(element, null).getPropertyValue('background-image');
if (bgImg == 'none') {
continue;
}
var match = bgImg.match(/url\((.+)\)/);
var image = {
url : match[1].replace(/\"/g, ''),
source : element
};
var index = images.push(image) - 1;
var el = new Image();
el.src = image.url;
el.onload = (function(images, index) {
return function(event) {
images[index].d = [this.width, this.height].join('×');
if (images.length - 1 == index) {
for (var k = 0; k < images.length; k++) {
var image = images[k];
var slice = image.url.match(/^.+\/(.+)\./)[1];
console[(!image.d) ? 'group' : 'groupCollapsed'](image.url);
console.log(slice);
for (var prop in image) {
(prop != 'url') && console.log(image[prop]);
}
console.groupEnd(image.url);
}
}
}
})(images, index);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment