Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

Save a python script like this:

#!/usr/bin/python
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

im.save(sys.argv[2])

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.

share|improve this answer
    
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 '11 at 18:46
    
No problem, I hope it works for you! –  Brad Pitcher Nov 9 '11 at 18:42
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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