diff --git a/tinycolor.js b/tinycolor.js index 9ce79d84..d3c2ea41 100644 --- a/tinycolor.js +++ b/tinycolor.js @@ -140,6 +140,13 @@ tinycolor.prototype = { "rgb(" + mathRound(bound01(this._r, 255) * 100) + "%, " + mathRound(bound01(this._g, 255) * 100) + "%, " + mathRound(bound01(this._b, 255) * 100) + "%)" : "rgba(" + mathRound(bound01(this._r, 255) * 100) + "%, " + mathRound(bound01(this._g, 255) * 100) + "%, " + mathRound(bound01(this._b, 255) * 100) + "%, " + this._roundA + ")"; }, + toCmyk: function() { + return rgbToCmyk(this._r, this._g, this._b); + }, + toCmykString: function() { + var cmyk = rgbToCmyk(this._r, this._g, this._b); + return "cmyk(" + Math.round(cmyk.c * 100) + "," + Math.round(cmyk.m * 100) + "," + Math.round(cmyk.y * 100) + "," + Math.round(cmyk.k * 100) + ")"; + }, toName: function() { if (this._a === 0) { return "transparent"; @@ -548,6 +555,21 @@ function rgbaToArgbHex(r, g, b, a) { return hex.join(""); } +// `rgbToCmyk` +// Converts RGB color to CMYK +function rgbToCmyk(r, g, b) { + var R = r/255, + G = g/255, + B = b/255, + K = 1-Math.max(R, G, B); + return { + C: (1-R-K) / (1-K), + M: (1-B-K) / (1-K), + Y: (1-G-K) / (1-K), + K: K + }; +} + // `equals` // Can be called with any tinycolor input tinycolor.equals = function (color1, color2) {