TinyColor icon indicating copy to clipboard operation
TinyColor copied to clipboard

To/Get CMYK

Open Horray opened this issue 10 years ago • 5 comments

Why don't you add a conversion of type toCMYK() and getCMYK()? I think it will be very useful!

Here's rgbToCmyk and cmykToRgb:

function colorWheel_rgbToCmyk(r, g, b, normalized) {
    var c = 1 - (r / 255);
    var m = 1 - (g / 255);
    var y = 1 - (b / 255);
    var k = Math.min(c, Math.min(m, y));

    c = (c - k) / (1 - k);
    m = (m - k) / (1 - k);
    y = (y - k) / (1 - k);

    if (!normalized) {
        c = Math.round(c * 10000) / 100;
        m = Math.round(m * 10000) / 100;
        y = Math.round(y * 10000) / 100;
        k = Math.round(k * 10000) / 100;
    }

    c = isNaN(c) ? 0 : c;
    m = isNaN(m) ? 0 : m;
    y = isNaN(y) ? 0 : y;
    k = isNaN(k) ? 0 : k;

    return {
        c: c,
        m: m,
        y: y,
        k: k
    }
}

function colorWheel_cmykToRgb(c, m, y, k, normalized) {
    c = (c / 100);
    m = (m / 100);
    y = (y / 100);
    k = (k / 100);

    c = c * (1 - k) + k;
    m = m * (1 - k) + k;
    y = y * (1 - k) + k;

    var r = 1 - c;
    var g = 1 - m;
    var b = 1 - y;

    if (!normalized) {
        r = Math.round(255 * r);
        g = Math.round(255 * g);
        b = Math.round(255 * b);
    }

    return {
        r: r,
        g: g,
        b: b
    }
}

Can you add a full support for cmyk?

Horray avatar Dec 23 '15 20:12 Horray

why don't you make a pullrequest ?

don't forget about tests and documentation

jt3k avatar Mar 15 '16 07:03 jt3k

@jt3k I'm not fluent enough in JavaScript to do that. Can you please do that?

Horray avatar Mar 15 '16 16:03 Horray

@Horray what about your code. does it work?

jt3k avatar Mar 15 '16 17:03 jt3k

@jt3k I think it does. I just don't know where and how to add it to the tinyColor.js

Horray avatar Mar 16 '16 16:03 Horray

hi, any updates on that? I think it would be awesome for those who work in the print industry

josefanostylus avatar Dec 15 '17 19:12 josefanostylus