Created
October 9, 2017 12:48
-
-
Save GianlucaGuarini/6453ab520a32239cc46d52e6fc21319e to your computer and use it in GitHub Desktop.
Because devicePixelRatio is not relyable enough
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
const resolutions = [ | |
'data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=', | |
'data:image/gif;base64,R0lGODlhAQABAAAAACwAAAAAAQABAAA=', | |
'data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==', | |
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAAACklEQVQYV2P4DwABAQEAWk1v8QAAAABJRU5ErkJggg==', | |
]; | |
const img = document.createElement('img'); | |
img.src = resolutions[0]; | |
img.srcset = resolutions.map((itm, i) => `${itm} ${i + 1}x`).join(','); | |
export default function imageDpiResolution() { | |
return resolutions.indexOf(img.currentSrc || img.src) + 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment