I have an application I have developed which is generating RGB PNG images with text on them via imageMagic, like so:

convert -size 1000x1000 -density 300 xc:white -pointsize 24 \
  -fill "rgb(0,0,0)" -annotate +500+500 'Josh Test' Jtest.png

It's working great. However I need to be able to generate CMYK output as well, the same images, but in CMYK rather than RGB. InkScape can't do this. I thought I could just use a CMYK color:

convert -colorspace cmyk -density 300 xc:white -pointsize 24 \
  -fill "cmyk(0,0,0,0)" -annotate +500+500 'Josh Test' Jtest.pdf

However the resulting image is not 100% black, but 100% cyan, 100% magenta, 100% yellow and 0% black. Actual colors look even worse. This is because ImageMagic does all drawing in an RGB space and converts to CMYK:

Drawing requires the RGBA color model. Internally, images are stored as RGB(A) or CMY(A)K.

I cannot generate RGB images and convert to CMYK, the colors won't be right. They must be CMYK the whole way through. How can I generate CMYK images under linux?

1 Answer 1


Save a python script like this:

from PIL import Image, ImageFont, ImageDraw
import sys

im = Image.new('CMYK', (1000,1000), (0, 0, 0, 255))

f = ImageFont.load_default()
d = ImageDraw.Draw(im)
d.text((500, 500), sys.argv[1], font = f, fill = (0, 0, 0, 0))
del d


Dependencies are python and the python imaging library. Then you can create your images with this command:

python cmyktext.py "Josh test" Jtest.pdf

Don't forget that cmyk is subtractive, so (0,0,0,0) is actually white. It is of course also possible to use any font you like, as documented here.

  • 1
    Woah, if this works it will be awesome as I have one customer begging me to support CMYK. I'll test this soon. Thanks!
    – Josh
    Nov 8, 2011 at 18:46
  • No problem, I hope it works for you! Nov 9, 2011 at 18:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.