[Zope] PIL+Zope: what's wrong with this code ?

Jerome Alet alet@unice.fr
Fri, 1 Jun 2001 11:46:56 +0200 (MET DST)


Hi,

I plan to use PIL in an external method to retrieve Images from de ZODB
and transform them to PIL Images.

When I use the following code I've got an error which basically says: 

	"Not enough image data"

This seems to be a PIL error, not a Zope's one, but I really can't
understand what the problem is, except that I don't know what mode
parameter to pass to fromstring(), I've tried "1", "P", "RGB" etc... but
without luck:

--- CUT ---
import PIL.Image

# get the logo GIF Image from the ZODB
# This object exists and is OK when viewed from the ZMI 
logo = getattr(self, "logo")
imgdata = logo.data
if type(imgdata) is not type('') :
        temp = ''
        while imgdata is not None :
                temp = temp + imgdata.data
                imgdata = imgdata.next
        imgdata = temp
MyPILImage = PIL.Image.fromstring("1", (logo.width, logo.height), imgdata)
--- CUT ---

I'm really not sure about the two first parameters that the
PIL.Image.fromstring() function need, the first one is the mode, the
second is the size.

Could someone with a PIL+Zope experience show me a code snippet to convert
Zope Image objects (in any format) to PIL Images ?

Thanks in advance.

PS: I use Zope 2.3.2 and PIL 1.1.1

Jerome Alet - alet@unice.fr - http://cortex.unice.fr/~jerome
Fac de Medecine de Nice        http://wwwmed.unice.fr 
Tel: (+33) 4 93 37 76 30     Fax: (+33) 4 93 53 15 15
28 Avenue de Valombrose - 06107 NICE Cedex 2 - FRANCE