Skip to content

Instantly share code, notes, and snippets.

@michelle
Created April 28, 2014 06:46
Show Gist options
  • Save michelle/11363541 to your computer and use it in GitHub Desktop.
Save michelle/11363541 to your computer and use it in GitHub Desktop.
RGB to CMYK (rough)
function rgbtocmyk(r, g, b) {
if (!r && !g && !b) {
return [0, 0, 0, 1]
}
var c = m = y = k = 0;
c = 1 - (r/255);
m = 1 - (g/255);
y = 1 - (b/255);
var min = Math.min(Math.min(c, m), y);
var denom = 1 - min;
c = (c - min) / denom;
m = (m - min) / denom;
y = (y - min) / denom;
k = min;
return [c, m, y, k];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment