Skip to content

Instantly share code, notes, and snippets.

@jasoncartwright
Created September 3, 2012 09:22
Show Gist options
  • Save jasoncartwright/3608074 to your computer and use it in GitHub Desktop.
Save jasoncartwright/3608074 to your computer and use it in GitHub Desktop.
Retina image swap-out for Google-hosted images
if (window.devicePixelRatio > 1) {
img_re = new RegExp(/=(s|w)(\d*)(\-c)?$/)
$("img").each(function(id, el){
img_src = $(el).attr("src")
if (img_re.test(img_src)) {
img_size = parseInt(img_src.match(img_re)[2])
dimension = img_src.match(img_re)[1]
new_img_size = img_size*2
new_src = img_src.replace(img_re,"=" + dimension + new_img_size)
$(el).attr("src",new_src)
}
})
}
@jasoncartwright
Copy link
Author

jasoncartwright commented Nov 26, 2014

Worth noting that we don't use this technique anymore - it's all picture element and http://scottjehl.github.io/picturefill/ now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment