Created
February 28, 2012 03:00
-
-
Save minikomi/1929015 to your computer and use it in GitHub Desktop.
Get rgb color from css color name
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
var name2rgb = function(str){ | |
var canv=document.createElement("canvas"); | |
canv.height = 1; canv.width = 1; | |
var ctx = canv.getContext("2d"); | |
ctx.fillStyle="rgba(1,1,1,0.1)"; | |
ctx.fillRect(0,0,1,1); | |
ctx.fillStyle=str; | |
ctx.fillRect(0,0,1,1); | |
var pxl= ctx.getImageData(0,0,1,1).data; | |
if(pxl[3] === 47){ | |
return"Sorry, that color doesn't exist."; | |
} else { | |
return "rgb("+pxl[0]+", "+pxl[1] +", " +pxl[2]+")"; | |
} | |
} |
haha.. thought of a much less stupid way to do it
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
OMG DO IT IN COFFEESCRIPT!!!