How to export SVG with accurate CMYK

edited June 2016 in How To...


So I'm working with the standard SVG export library of processing (mostly to achieve scaleable graphics so pdf would be fine too)

Now I'd like to set a color in CMYK and print the SVG output with that color. A couple questions: - I've read that using a formula will only give a very rough approximation of cmyk, how would I implement ICC color profiles in Processing? - If I choose a color in CMYK and draw in the sketch using the translated RGB value, will the then exported file have the correct CMYK color value?

Many thanks!


` import java.awt.color.ColorSpace; import java.awt.color.ICC_ColorSpace; import java.awt.color.ICC_Profile; import; import java.util.Arrays; import processing.svg.*;

float[] cmykColor = {0.0, 1.0, 0.0, 0}; float[] rgbColor;

void setup(){ size(400,400); rgbColor = CMYKtoRGB( cmykColor ); }

void draw(){ beginRecord(SVG, "test.svg"); fill( rgbColor[0], rgbColor[1], rgbColor[2] ); //println( red(rgbColor), green(rgbColor), blue(rgbColor) ); rect(0,0, width, height); endRecord(); }

float[] CMYKtoRGB( float[] cmyk ){ try { // The "from" CMYK colorspace println(dataPath("") + "\" + "CoatedFOGRA27.icc" ); ColorSpace cmykColorspace = new ICC_ColorSpace(ICC_Profile.getInstance( dataPath("") + "\" + "CoatedFOGRA27.icc" )); // The "to" RGB colorspace ColorSpace rgbColorspace = new ICC_ColorSpace(ICC_Profile.getInstance( dataPath("") + "\" + "AdobeRGB1998.icc"));

    // Bring in to CIEXYZ colorspace (refer to Java documentation:
    float[] ciexyz = cmykColorspace.toCIEXYZ(cmyk);
    println("ciexyz", ciexyz ); 
    float[] thisColorspace = rgbColorspace.fromCIEXYZ(ciexyz);
    println("thisColorSpace", thisColorspace); 
    float[] rgb = rgbColorspace.toRGB( thisColorspace );
    println("rgb", rgb[0], rgb[1], rgb[2]);
    float[] c = { rgb[0] * 255, rgb[1] * 255, rgb[2] * 255 };

    // Format RGB as Hex and return
    return c;//String.format("#%06x", c.getRGB() & 0xFFFFFF);
} catch (IOException e) { e.printStackTrace(); }
return new float[] {0, 0, 0};

} `

I've tried to use the above code but when I export from processing and use the color picker in Illustrator it tells me I'm not using CMYK(0,1,0,0) but CMYK(0, 0.91, 0.1, 0)

Does anyone know why this could be?

Sign In or Register to comment.