-
-
Save southill/8c0bd596d3d39da6c4acfb6e3a3d3e50 to your computer and use it in GitHub Desktop.
Extract a set of image information from a webpage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let imgData = Array.from(document.getElementsByTagName("img")) | |
.map(v => { | |
var rect = v.getBoundingClientRect(); | |
var vHeight = (window.innerHeight || doc.documentElement.clientHeight); | |
var vWidth = (window.innerWidth || doc.documentElement.clientWidth); | |
var vDPR = window.devicePixelRatio; | |
return { | |
src: v.currentSrc, | |
cssWidth: v.clientWidth, | |
naturalWidth: v.naturalWidth, | |
cssHeight: v.clientHeight, | |
naturalHeight: v.naturalHeight, | |
hidden: !(v.offsetParent != null), | |
bottom: rect.bottom, | |
height: rect.height, | |
left: rect.left, | |
right: rect.right, | |
top: rect.top, | |
width: rect.width, | |
srcset: v.srcset, | |
sizes: v.sizes, | |
isPicture: (v.parentNode.nodeName === "PICTURE"), | |
vWidth: vWidth, | |
vHeight: vHeight, | |
vDPR: vDPR, | |
ratioWidth: (v.naturalWidth / v.clientWidth).toFixed(1), | |
ratioHeight: (v.naturalHeight / v.clientHeight).toFixed(1), | |
pixelWaste: (v.naturalHeight - v.clientHeight) * (v.naturalWidth - v.clientWidth) | |
}; | |
}); | |
return return JSON.stringify(imgData); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment