Created
October 16, 2014 20:27
-
-
Save jamesdaniels/bedf2227f10b75c52eb7 to your computer and use it in GitHub Desktop.
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
// This will grab the largest image for the pixelRatio without oversampling (iOS style) | |
// Usage: assetUsingNativePixelRatio('/assets/images', 'logo', 'png', [1,2,3]); | |
// Output: /assets/images/[email protected] | |
function assetUsingNativePixelRatio(path, name, extension, pixelRatios) { | |
// Sort the pixelRatios in case they were put in the wrong order | |
var $pixelRatios = $(pixelRatios).sort(); | |
// Price is right style | |
var matchingPixelRatio = $pixelRatios.not(function() { | |
return (this > window.devicePixelRatio); | |
}).last()[0]; | |
// Append everything together but if the pixel ratio is 1x don't put an "@1x" that's just silly | |
return (path + '/' + name + (matchingPixelRatio > 1 ? ('@' + matchingPixelRatio + 'x') : '') + '.' + extension); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment