Created
August 19, 2013 14:31
-
-
Save thekarel/6269778 to your computer and use it in GitHub Desktop.
Replace <img> src with retina src
From http://www.kylejlarson.com/blog/2012/creating-retina-images-for-your-website/
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
<img class="hires" alt="" src="search.png" width="100" height="100" /> | |
<script type="text/javascript"> | |
$(function () { | |
if (window.devicePixelRatio == 2) { | |
var images = $("img.hires"); | |
// loop through the images and make them hi-res | |
for(var i = 0; i < images.length; i++) { | |
// create new image name | |
var imageType = images[i].src.substr(-4); | |
var imageName = images[i].src.substr(0, images[i].src.length - 4); | |
imageName += "@2x" + imageType; | |
//rename image | |
images[i].src = imageName; | |
} | |
} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment