[reportlab-users] Non-JPEG CMYK images

Stevens, Ian IStevens at globeandmail.com
Mon Feb 25 18:10:55 EST 2008


In addition to complaining about RGB text, our printer is complaining
about RGB images. The thing is, these are TIFF images which are
actually CMYK. Reportlab is converting them to RGB in
reportlab.pdfgen.pdfimages.PDFImage.PIL_imagedata(). I couldn't find a
way to stop this, but I came across an old discussion at
http://two.pairlist.net/pipermail/reportlab-users/2003-October/002137.ht
ml. The CMYK support for JPEG images has long since been completed, but
is obviously incomplete for PIL images, which are just converted to RGB.

I probably don't have a full grasp of the implications of CMYK support
for PIL images, but would it make sense to treat them as JPEG images are
currently treated? (ie. use the colorspace within the image itself) I
made a naive change to the code and it seems to have fixed the PDF
colorspace for our CMYK images. (ie. they are now as CMYK in the PDF,
not RGB)

What follows is the patch I'm using. I don't know exactly what PIL
image modes of '1', 'L', 'RGBX' or 'RGBA' mean in this context, so those
modes get converted to 'RGB':

98c98,107
< myimage = image.convert('RGB')
---

>

> # Use the colorspace in the image

> mode = image.mode

> if mode == 'CMYK':

> myimage = image

> colorSpace = 'DeviceCMYK'

> else:

> myimage = image.convert('RGB')

> colorSpace = 'RGB'

>

104c113
< imagedata=['BI /W %d /H %d /BPC 8 /CS /RGB /F [/A85 /Fl] ID' %
(imgwidth, imgheight)]
---

> imagedata=['BI /W %d /H %d /BPC 8 /CS /%s /F [/A85 /Fl] ID' %

(imgwidth, imgheight, colorSpace)]

Ian.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://two.pairlist.net/pipermail/reportlab-users/attachments/20080225/c31d93f8/attachment.html>


More information about the reportlab-users mailing list