Skip to content

Instantly share code, notes, and snippets.

@andymason
Created April 20, 2012 15:47
Show Gist options
  • Save andymason/2429828 to your computer and use it in GitHub Desktop.
Save andymason/2429828 to your computer and use it in GitHub Desktop.
var images = document.getElementsByTagName('img');
for (var i = 0; i < images.length; i++) {
var img = images[i];
var extPos = img.src.search(/\.[a-z]+$/gi);
var tmpImg = document.createElement('img');
var retinaURI = img.src.slice(0, extPos) + '@2x' + img.src.slice(extPos);
tmpImg.setAttribute('src', retinaURI);
tmpImg.onload = (function(img) {
return function() {
img.setAttribute('width', elm.width * 2);
img.setAttribute('height', img.height * 2);
img.setAttribute('src', this.src);
}
}(img));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment