[reportlab-users] Non-JPEG CMYK images

Stevens, Ian IStevens at globeandmail.com
Tue Feb 26 10:57:07 EST 2008


Sorry ... I had thought I had included the filename. This is patched
from r323 in trunk/reportlab/pdfgen/pdfimages.py.

The way I understand is that when an image is added either directly on
the canvas or as a flowable, Canvas.drawInlineImage() is called. That
in turn creates a PDFImage object, passing in the image to the
constructor. From there, PDFImage.getImageData() is called, which
determines whether the image is a string, file or PIL object. If it's a
PIL object, PDFImage.PIL_imagedata() is called, which converts the image
to RGB. That's the method I've patched.

I didn't know about ImageReader. I suppose I could try to wrap my PIL
image around that, but I suspect it will also convert the image to RGB,
given that the first thing Canvas.drawImage() does is call
ImageReader.getRGBData().

Ian.


> -----Original Message-----

> From: reportlab-users-bounces at reportlab.com

> [mailto:reportlab-users-bounces at reportlab.com] On Behalf Of

> Robin Becker

> Sent: Tuesday, February 26, 2008 6:34 AM

> To: Support list for users of Reportlab software

> Subject: Re: [reportlab-users] Non-JPEG CMYK images

>

> Stevens, Ian wrote:

> .........

> >

> > 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)]

> >

> .......

> it's a bit hard to figure out what you're patching without

> either of the filename and or svn version :)

>

> I looked in the latest trunk code and the ImageReader object

> has this if sys.platform[0:4] == 'java':

> ........

> else:

> im = self._image

> mode = self.mode = im.mode

> if mode=='RGBA':

> self._dataA = ImageReader(im.split()[3])

> im = im.convert('RGB')

> self.mode = 'RGB'

> elif mode not in ('L','RGB','CMYK'):

> im = im.convert('RGB')

> self.mode = 'RGB'

> self._data = im.tostring()

>

> so in the PIL branch we're trying to preserve the existing

> mode. Are you saying that even so the PIL images get

> converted somewhere else to RGB? I suspect that would not be

> intended, but this image stuff is fairly horrendous.

> --

> Robin Becker

> _______________________________________________

> reportlab-users mailing list

> reportlab-users at reportlab.com

> http://two.pairlist.net/mailman/listinfo/reportlab-users

>



More information about the reportlab-users mailing list