1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

convert pdf colors from RGB to CMYK

Discussion in 'PHP' started by varun8211, Sep 13, 2007.

  1. #1
    Is there any php script/function to change the color odf PDF from RGB to CMYK ?
    SEMrush
     
    varun8211, Sep 13, 2007 IP
    SEMrush
  2. sea otter

    sea otter Peon

    Messages:
    250
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I'm not sure what you mean by "color odf PDF", but here's a php function to convert from RGB to CMYK. What you do with the resulting array is up to you.

    
    /*
    	Converts an array of RGB data to CMYK data.
    	
    	Parameters:
    		$rgb	- 	an array of color information where
    					$rgb[0] == red value
    					$rgb[1] == green value
    					$rgb[2] == blue value
    	Returns:
    		array containing cmyk color information:
    			$array[0] == cyan value
    			$array[1] == magenta value
    			$array[2] == yellow value
    			$array[3] == black value
    */
    function RGB_to_CMYK($rgb)
    {
        $cyan = 1 - ($rgb[0] / 255);
        $magenta = 1 - ($rgb[1] / 255);
        $yellow = 1 - ($rgb[2] / 255);
    
        $min = min($cyan, $magenta, $yellow);
        
    	if ($min == 1)
            return array(0,0,0,1);
    
        $K = $min;
        $black = 1 - $K;
    
    	return array
    	(
    		($cyan - $K) / $black,
    		($magenta- $K) / $black,
    		($yellow - $K) / $black,
    		$K
    	);
    }
    
    PHP:
     
    sea otter, Sep 14, 2007 IP
  3. ErectADirectory

    ErectADirectory Guest

    Messages:
    656
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I would be utterly amazed if that is all there is to converting RGB to cmyk. I figured that photoshop, etc. would have a complex algorithm for this.

    varun - if correct, the above function would do absolutely nothing for your conversion hopes. All that is doing is changing 1 color to another (RGB --> CMYK) not converting a pdf or even a picture.

    Being a graphic artist and a programmer, I can honestly tell you that I have looked and found nothing that will automate this process. If you are building the PDFs server side from a group of pictures and text it would be possible to convert the pictures then build the PDF in cmyk but if you already have a rendered PDF, it's not going to happen (to the best of my knowledge).

    Good luck
     
    ErectADirectory, Sep 14, 2007 IP
  4. sea otter

    sea otter Peon

    Messages:
    250
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Well...yes and no.

    The algorithm is simple, and what I posted is it. That said, doing something useful with the output is another matter.

    The conversion doesn't take into account any of the real-world factors you and I deal with every day: rich black, saturation, bleed, ICC profiles (for acquisition, display and output), and more.
     
    sea otter, Sep 14, 2007 IP
    ErectADirectory likes this.