CMYK conversion with Linux

Earlier this month, I presented my entries for the IMAGINE constest and I promised to write another article about CMYK color space conversion under Linux. And now, here it is. Converting is important, if you want to know how your design looks printed – you can’t print all RGB colors –, and if you want to assure, that the image colors aren’t totally messed up.

For the cover design I worked with GIMP, a free alternative for Photoshop, if you don’t want to afford Adobe’s software and/or you don’t want to take up the challenge of running it through WINE (same goes for Illustrator of course). But although GIMP is a great tool, it has some shortcomings compared with its commercial brother. One of these is working with CMYK color space. With Photoshop, you can do a conversion from RGB to CMYK colors easily. With GIMP it is problematic and one of the reasons, why it is no serious competitor for the Adobe product. GIMP’s native colorspace is sRGB, thus all data is displayed in sRGB.

The Separate+ method

Image from GIMP Plugin Registry Separate+ page

To overcome this problem there is the Separate+ plugin, which devides images into the color components of the destination space. Basically, in the plugin’s dialog (Image > Separate > Separate) you choose the source and the destination color space and the algorithm to use for the conversion of the selected layer. You might want to do some research on how the algorithms work, and of course it’s a good idea to give all of them a try with an example, both with and without black point compensation (BPC). Also check the “Make CMYK pseudo-composite” option, otherwise you will only see the gray layers of the separated colors. You will notice, that the results may differ. But most important, they can differ a lot from your original image. Therefore, I searched for others ways of achieving a color space correction.

Other programs with CMYK conversion support

The good news: There are other programs to do the color conversion. But, to name the bad part, they are mainly vector-oriented. For example, you could use Inkscape together with scribus. Inkscape can’t separate the colors, but it is possible to save the colors in the space of a chosen ICC profile. Then you import the file to Scribus, which supports color separation and CMYK. If you want to have a CMYK PDF, you can install the ExportPDFCMYK extension, which uses ImageMagick for conversion, and export directly with Inkscape.
Instead of Scribus, you could also import files to sK1. sK1 has internal CMYK support and exports to postscript. Xara LX has CMYK support as well and does a reliable job according to the developers.

Working with the command line

Above, I already mentioned ImageMagick. The tool produces rasterized output, so it might not be the right choice for vector conversions. For PDF and PS output, it uses Ghostscript. To obtain a CMYK EPS image from an EPS input file, use

convert -colorspace cmyk -density 300 input.eps eps3:output.eps

where input.eps is the original image and output.eps is the resulting CMYK converted image. The term in front of the specified output file tells the converter to write the file as level 3 EPS file (the current PostScript standard).
Besides the color space parameter, you should also set the resolution, which is specified by the -density parameter with the default unit dots/inch.
Despite the correct resolution however, the result is grainy compared with the original when converting EPS. There are further conversion parameters you could apply, but you don’t want to lose to much time to find the right settings, do you?

So why not use Ghostscript directly, instead of accessing it through ImageMagick? Besides bitmap conversion, Ghostscript is also capable of converting vectors, which means the output will be vector, too. For the conversion of an EPS into CMYK space type

gs -o output.eps -sDEVICE=eps2write -r300 \
-dDEVICEWIDTHPOINTS=835 -dDEVICEHEIGHTPOINTS=833 \
-sColorConversionStrategy=CMYK input.eps

Here, the first parameter is the output file, followed by the device to use. For conversion to EPS use eps2write as its output quality is superior to the old epswrite device, for a conversion to PDF use pdfwrite. To view all devices available, you can call gs –help. Optionally, with -r you might want to change the resolution, which is given in dots/inch again.
The second line can be omitted in this example as it is only used, when you want to adapt or retain the page size, which is the case when converting to PDF. The unit is 1/72″. You can find the right values, if you open your input file in a text editor and watch out for the BoundingBox.
Line 3 shows the parameter for the color conversion -sColorConversionStrategy (other possible color spaces are RGB and Gray) and the input file.
The overall output is considerably better than the conversion with ImageMagick.

After executing these commands, you might be uncertain if the commands really worked because the output looks similar to the input. But there are ways to ascertain that the colors were recalculated. We can use Ghostscript for the evaluation as well:

gs -q -o – -sDEVICE=ink_cov input.eps

The ink_cov device returns the ink coverage. We don’t need an output file, so writing -o – suppresses an output, -q drops further unnecessary output on the command line. A difference between the coverages of the original and the converted file indicates a successful conversion. The output is presented in percentages of the ink color coverages, where the color order is C-M-Y-K:

16.91194 17.45447 13.95750 17.35352 CMYK OK
16.87010 17.41236 13.92877 17.41771 CMYK OK

The first line shows the file coverage of the original file, the second line the output for the converted file.

Another option is, again, the use of ImageMagick. With the compare tool writing the command

compare original.eps converted.eps diff.eps

we can generate a diff-file – in this case an EPS, but we could also use another file format – where all points with differing values in the original and converted images are marked red. For better interpretation the original image is inserted gray-colored in the background.
In the graphic on the right, you can only observe the red marking and the image in the background. If the red marks were less, you would see that the background image is grayed.

Closing Statement

I hope, this will be useful for anyone someday. I experimented a lot and I hope, I made no mistakes. Concluding, here is the list of software and versions used; you see I focused on the command line:

  • GIMP 2.8.10-1
  • Inkscape 0.48.5-2
  • ImageMagick 6.8.9.5-1
  • Ghostscript 9.14-1

Of course, there are also ways of handling conversion with ICC profiles in Ghostscript and ImageMagick, but this to much for now. There is a screencast for Inkscape related stuff, which explains ImageMagick conversion with ICC profiles as well as another CMYK conversion tool.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s