is there anyone know that converting an image color format rgb to cmyk.

Thanks for help.

    i am uploading rgb color format images to server then i want to convert it to CMYK for print. i will not display it.

    thanks.

      There isn't a built in function to do this for you, you'll need to write something to do it, and to write out a file.

      Using GD2's imagecolorat() function you can get the colour of a pixel in an image in RGB. You can then use the RGB->CMY algorithm found here: http://www.easyrgb.com/math.php?MATH=M11#text11 to get to CMY, and then theres a CMY -> CMYK algorithm to do the final step. To write out a CMYK file you'll need to find an appropriate file format specification (TIFF? Targa?), and write some code to make the file.

      It's going to be a lot of work..

        thanks a lot for help.

        i find a code and i added it converting Algorithm.
        problem how i will create a new image with this CMYK value.
        Because imagecolorallocate is not allowed.

        Code is:

         <?
            $imgname = "imagecolor.jpg";
            $image = @imagecreatefromjpeg($imgname);
        
        $imagehw = GetImageSize($imgname);
        $imagewidth = $imagehw[0];
        $imageheight = $imagehw[1];
        
        print("Width : $imagewidth : Height : $imageheight <BR>");
        
        for ($row = 0 ; $row < $imageheight ; $row++)
        {
            for ($col = 0 ; $col < $imagewidth ; $col++)
            {
                $rgb = ImageColorAt($image, $col, $row);
                $r = ($rgb >> 16) & 0xFF;
                $g = ($rgb >> 8) & 0xFF;
                $b = $rgb & 0xFF;
        
        
                /*  RGB —> CMY  */
                $C = 1 - ( $r / 255 );
                $M = 1 - ( $g / 255 );
                $Y = 1 - ( $b / 255 );
        
        
        
                /*  CMY —> CMYK  */
                $var_K = 1;
        
                if ( $C < $var_K )   $var_K = $C;
                if ( $M < $var_K )   $var_K = $M;
                if ( $Y < $var_K )   $var_K = $Y;
        
                $C = ( $C - $var_K ) / ( 1 - $var_K );
                $M = ( $M - $var_K ) / ( 1 - $var_K );
                $Y = ( $Y - $var_K ) / ( 1 - $var_K );
                $K = $var_K;
        
                print("$row : $col -- $C : $M : $K :$K<BR>");
            }
        }
        
        ?>

        And output is:

        Width : 426 : Height : 254
        0 : 0 -- 0 : 0.30588235294118 : 0 :0
        0 : 1 -- 0 : 0.34509803921569 : 0 :0
        0 : 2 -- 0 : 0.30801687763713 : 0.070588235294118 :0.070588235294118
        0 : 3 -- 0 : 0.25957446808511 : 0.07843137254902 :0.07843137254902
        0 : 4 -- 0 : 0.23504273504274 : 0.082352941176471 :0.082352941176471
        0 : 5 -- 0 : 0.23788546255507 : 0.10980392156863 :0.10980392156863
        0 : 6 -- 0 : 0.25217391304348 : 0.098039215686274 :0.098039215686274
        ..................

          You'd have to convert it back into RGB, then.

            Hi,

            i want to create a CMYK color mode image.
            How i will create, is there a function or command in php
            is there anyone know this subject.

            Thanks for all help...

              Write a Reply...