Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,892 questions

51,823 answers

573 users

How to convert RGB to CMYK in PHP

1 Answer

0 votes
function RGBtoCMYK($R, $G, $B) {
    if ($R == 0 && $G == 0 && $B == 0) {
        return array(0, 0, 0, 1);
    }
    
    $R = $R / 255.0 * 100;
    $G = $G / 255.0 * 100;
    $B = $B / 255.0 * 100;
    $K = 100 - max(array((int)$R, (int)$G, (int)$B)); 
    
    if ($K == 100) {
        return array(0, 0, 0, 100);
    }
    
    $C = abs(round((100 - $R - $K) / (100 - $K) * 100));
    $M = abs(round((100 - $G - $K) / (100 - $K) * 100));
    $Y = abs(round((100 - $B - $K) / (100 - $K) * 100));
    
    return array($C, $M, $Y, $K);
}

$CMYK = RGBtoCMYK(245.0, 213.0, 0.0);

echo json_encode($CMYK);



/*
run:

[0,13,100,4]

*/

 



answered Feb 2, 2023 by avibootz

Related questions

1 answer 92 views
92 views asked Jan 31, 2023 by avibootz
1 answer 123 views
123 views asked Feb 1, 2023 by avibootz
1 answer 120 views
120 views asked Feb 1, 2023 by avibootz
1 answer 125 views
125 views asked Jan 31, 2023 by avibootz
1 answer 137 views
137 views asked Jan 31, 2023 by avibootz
1 answer 95 views
95 views asked Jan 31, 2023 by avibootz
1 answer 115 views
115 views asked Jan 31, 2023 by avibootz
...