[reportlab-users] PIL frombuffer question

Paul Guse paul at mustagh.com
Fri Mar 9 10:54:38 EST 2007



> Paul Guse wrote:

>> Well I partially answered my own question. I can get a pixel buffer to

>> write to the canvas as an image with the following code:

>>

>> mode = 'RGB'

>> img = PIL.Image.frombuffer (mode, (100,100), b, "raw", mode, 0, 1)

>> img.fp = ""

>>

>> i = ImageReader (img)

>> c.drawImage (i, 100, 100, 100, 100)

>>

>> If I don't set img.fp I get an attribute error. This draws the image to

>> the pdf correctly.

>> Anyways, this seems like a bit of a hack, and I'm sure there's a better

>> way to do it. Also, it would be great to be able to create a platypus

>> flowable out of a pixel buffer.

>> Does anyone have any tips for doing this?

>>

>> Paul

>>

> .......

>

> We're probably assuming something about how Pil images are used in the

> ImageReader class. However, this must be a kind of strange way to do

> things. Why

> draw into a pixel buffer when you can draw directly to the pdf?

> --


I'm using python as an embedding scripting language and I don't want to
rewrite all my drawing classes to draw in python too. Trying to keep python
isolated and only expose a general interface class. So objects can draw
normally without knowing about python, but the pixel data from that draw can
be used as an image by python.
I found a way to make this work. I just made my own flowable image class.
Ripped the platypus Image class and modified it to take a pixel buffer,
create an ImageReader object, and draw that image. Seem to work well.




> Robin Becker



>




More information about the reportlab-users mailing list