[reportlab-users] Patch: PIL images with ReportLab

Sam Hunter shunter at dbsupply.com
Thu Apr 28 14:10:32 EDT 2005

  I like the idea that all passed image references be acceptable to 
ImageReader's constructor.  This could simplify things like the 
PDFImageXObject class quite a bit.  It seems like things are already 
somewhat set up in this way, but a few small connections are missing to 
make the wrapping dissapear from user space alltogether.  In general, I 
lean towards writing  objects so that they handle repetitive tasks for 
me automatically.  In a document with a lot of images, wrapping each 
ends up being kind of repetitive.  I find that having the object do it 
automatically keeps me from forgetting and having problems later (Python 
IS the lazy programmer's language right?).  It would also undoubtedly 
cut down on confusion if users could pass most of the more common image 
types dirrectly to drawImage().  In my searches for a solution to this 
problem I've found a lot of posts asking how to do this.

  I am no expert on Python imaging libraries, but it seems like PIL is 
the biggest by far.  ImageReader already uses it as the default handler 
for anything that isn't JPEG.  If support for other things is needed it 
should not be too difficult to build that support into ImageReader to 
centralize special cases and avoid having them spread throughout the 
code as you rightly want to avoid.  As far as I can tell, ImageReader 
already supports everything that the other image methods need, so it 
seems like a natural choice as container for all types of image.

what do you think?


Robin Becker wrote:

> Sam Hunter wrote:
>> Okay I think we can have cake and eat it too.  With "ImageReader is 
>> the preferred  image type" idea in mind, how about just a small patch 
>> which detects if a PIL image is passed to drawImage(), and if so, 
>> wraps it in an ImageReader object which has the patch I previous 
>> posted.  This supports the idea of keeping ImageReader as the primary 
>> image type, allows PIL images to be used transparently, and 
>> streamlines things from the user's perspective.  I also don't think 
>> that it should cause a problem for Java related usage?
>> canvas.py,  drawImage(self, image, x, y, width=None, height=None, 
>> mask=None):
>> Original:
> ....
> I think that's the general idea; the question is should we allow only 
> ImageReaders/filenames to be passed in or some other types ie where 
> does the wrapping take place in user space or in a hidden fashion 
> inside the various methods. I suspect the users will say wrap it for 
> me and I'll want to make the users do it :)
> the difficulty for the internal wrap model is that if PIL then why not 
> other things. Or should we just say that the image reference passed in 
> should be acceptable to ImageReader's constructor?
> -- 
> Robin Becker

More information about the reportlab-users mailing list