Skip to content

Instantly share code, notes, and snippets.

@oslego
Last active December 19, 2015 08:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oslego/5926655 to your computer and use it in GitHub Desktop.
Save oslego/5926655 to your computer and use it in GitHub Desktop.
Convert a CSS Shape polygon path from pixels to ems
function convertPixelPathToEm(path){
return path.trim().split(/,\s?/).map(function(pair){
return pair.trim().split(/\s+/).map(function(value){
value = parseInt(value, 10);
value = (value === 0) ? 0 : (value / 16).toFixed(2)
return value + 'em'
}).join(' ')
}).join(', ')
}
var pxString = '99px 0px, 39px 71px, 60px 112px, 43px 154px, 117px 179px, 481px 0px, 99px 0px'
var emString = convertPixelPathToEm(pxString)
console.log(emString)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment