[reportlab-users] Inserting RGB image with CYMK color space using reportlab

Robin Becker robin at reportlab.com
Tue Jul 7 05:00:56 EDT 2015


On 06/07/2015 18:37, Tim Roberts wrote:
> Andy Robinson wrote:
>> Failing that, try to convert your image using Photoshop.   I don't
>> know what the algorithms are in PIL but have often noticed that
>> colours don't look so great after transformations in PIL.  If you need
>> to do it programmatically, ImageMagick is better.
>
> I can +1 this assessment from direct recent experience.  I do full-color
> glossy programs books for a local community theater.  I have one printer
> that I enjoy working with who needs all of the images to be CMYK.  In
> the past, I've done it by hand and found it to be tedious.  This year, I
> got smart and made a PIL script.  The results were very disappointing:
> the colors were pale and washed out.  I did the same conversion with
> ImageMagick and the results were excellent, although too late.  Lesson
> learned.
>
The problem with rgb-->cmyk is that there are an infinite number of ways to do 
it. In the reportlab.lib.colors module we use


> def rgb2cmyk(r,g,b):
> 	'''one way to get cmyk from rgb'''
> 	c = 1 - r
> 	m = 1 - g
> 	y = 1 - b
> 	k = min(c,m,y)
> 	c = min(1,max(0,c-k))
> 	m = min(1,max(0,m-k))
> 	y = min(1,max(0,y-k))
> 	k = min(1,max(0,k))
> 	return (c,m,y,k)


which appears to work for white and black :(


The PIL.ImageCms (based on http://www.cazabon.com/pyCMS/) module appears to 
support profile to profile conversions so if you have the profiles and the 
knowledge etc etc it should be possible to do the conversions pretty well. 
Unfortunately I'm not a style councellor so I don't have most of the 
understanding required.
--
Robin Becker


More information about the reportlab-users mailing list