Created
September 3, 2012 09:22
-
-
Save jasoncartwright/3608074 to your computer and use it in GitHub Desktop.
Retina image swap-out for Google-hosted images
This file contains hidden or 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
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) | |
} | |
}) | |
} |
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
Google App Engine uses get_serving_url [1] to produce an image URL [2] that can be resized by changing the last digits. This javascript detects is its running on a device capable of displaying 'retina' images and swaps out the img src to one double the size. You can see this running on the Potato website [3].
[1] https://developers.google.com/appengine/docs/python/images/functions
[2] E.g. http://lh5.ggpht.com/IFPH6YSiPKtCp1HZtIFr3R21i_Cgjmqfq-9sBsY03QvQZEcnvu-xYPvi8rINATms6Rdlrt3Jjn1az4R8EkbsdQ=s220
[3] http://p.ota.to/work/google-art-project/