[Zope] Re: [Image-SIG] Installing PIL on Windows

Julian Melville jmelville@selectaustralasia.com.au
Mon, 1 Jul 2002 17:49:53 +1000


> It would be great if someone could post a how-to readable by newbies that
> specifically linked to the current versions of all needed files instead of
> another endless search of 'somewhere in the sourceforge site'.

OK, here's my solution. So far, this seems to have worked fine (i.e. I can
run the thumbnailer script below without a problem). I didn't actually have
any problems with PIL so far other than finding that I needed to install the
Tcl DLLs mentioned below...

I have...

 - Windows 2000 Server SP2 (in case it matters)
 - Zope 2.5.1 (just the regular downloaded binary) installed on it.
 - Another machine with a regular install of Python. Could be the same
machine as the server, I guess - but I used my workstation.
 - PIL from Pythonware. The link is "Python Imaging Library 1.1.2 for Python
2.1.1" and the file is called "py21-pil-1.1.2-20010910.exe"

Install the downloaded PIL on the other machine and you'll get some files in
C:\py21.

Put the _imaging.pyd file from C:\py21\DLLs into Zope\bin\lib\win32. You
don't need the _imagingtk.pyd file because Zope doesn't do Tk stuff.

You need to copy the tcl83.dll and tk83.dll files from the regular install
of Python into Zope\bin\lib\win32. If you don't do this, the server throws
DLL errors on the console. I have no idea why it needs the Tk DLL, but it
does!

Put the entire PIL directory in Zope\lib\python.

Restart your Zope and then try something out. I used a thumbnailer script
from a recipe at ZopeLabs, installed in the Extensions folder and referenced
with an External Method:

---------------------------------
import PIL.Image
import cStringIO

def make_thumb(self, image, width, height):

	""" make a thumbnail from a Zope image """

	oriImage = self.restrictedTraverse(image)
	oriFile = cStringIO.StringIO(oriImage.data)

	image = PIL.Image.open(oriFile)
	image.thumbnail((int(width), int(height)))
	image_type = image.format

	thumbnailImage = cStringIO.StringIO()
	image.save(thumbnailImage, image_type)
	thumbnailImage.seek(0)

	return thumbnailImage.getvalue()
---------------------------------

Let me know if it works or if I just got lucky. Oh, the only credit I take
for this is adding the Tcl and Tk dlls, everything else I found on assorted
mailing list archives somewhere (I forget now).

Cheers,

Julian.

___________
Julian Melville
Select Australasia
mailto:jmelville@selectaustralasia.com.au
http://www.selectaustralasia.com.au/