[Zope] installing PIF in win32 zope

Rodrigo Dias Arruda Senra rodsenra at gpr.com.br
Fri Feb 4 07:41:27 EST 2005


Ian Hood wrote:
 > I am a newbie working through the zope book and tutorials.
 > The zope book examples regarding Image manipulation states that the
 > python PIF is required.

I suppose you want PIL == Python Image Library instead of PIF!
http://www.pythonware.com/products/pil/

I do not know about any PIF in Zope/Python context.

 > The only info I can find for installing PIF is Unix/Linux oriented..

I believe it'll be easier for a newbie to use PIL modules from
Zope ExternalMethods.

- Install PIL in Windows from binaries (site mentioned above).

- Just create a file in <Zope install path>\Extensions,
and inside ZMI (Zope Management Interface) create a ExternalMethod 
object that maps to a function inside the prior file.

The file that contains the function bound to the ExternalMethod
inside Zope could look like the following example:

<myfile.py>
import os
from StringIO import StringIO
from PIL import Image, ImageDraw, ImageFont, ImageFilter, ImageChops
# to insert Images inside Zope
from OFS.Image import manage_addImage

def make_label(label, fontname, fontsize,
                fg=(0,0,0), bg=(0,0,0), transp=10):
     """Return StringIO object with a image that
     represents a transparent label"""
     font = ImageFont.truetype(fontname ,fontsize)
     Img=Image.new("L", (10,10),0)
     color_list = []
     for c in bg+fg:
         color_list.append(c)
     Img.putpalette(color_list)
     draw = ImageDraw.Draw(Img)
     sizex, sizey = draw.textsize(label,font=font)
     Img = Img.resize((sizex,sizey))
     draw = ImageDraw.Draw(Img)
     bimsize = (sizex, sizey)
     width,height = bimsize
     xoff = yoff = 0
     draw.text((xoff,yoff), label, fill=1, font=font)
     imgfile = StringIO()
     Img.save(imgfile,'png', transparency=transp)
     imgfile.seek(0,0)
     del Img
     return imgfile

def zope_make_label(self, oid, label, fontname, fontsize,
                     fg, bg, transp):
     imgfile = make_label(label, fontname, fontsize, fg, bg, transp)
     manage_addImage(self, oid, imgfile)
     del imgfile
</myfile.py>

best regards,
Senra

-- 
Rodrigo Senra
MSc Computer Engineer     rodsenra at gpr.com.br
GPr Sistemas Ltda       http://www.gpr.com.br



More information about the Zope mailing list