You are not logged in Log in Join
You are here: Home » Members » regebro » Using PIL with Zope

Log in
Name

Password

 

Using PIL with Zope

PIL is an awsome product from SecretLabs with installation scripts that isn't nearly as good as the rest of the product. This makes it a pain to install, so here is some hints on how to do this, specifically how to get JPG support working and installing it for usage with Zope.

0. Download PIL and unpack

You can get PIL from here: http://www.pythonware.com/downloads/Imaging-1.1.2.tar.gz Unpack: gunzip -c Imaging-1.1.2.tar.gz | tar xvf -

1. Check for zlib.

Run these commands, and note which of them that works.

ld -L/usr/local/lib -lz -nostdlib
ld -L/usr/lib -lz -nostdlib

If it writes '-lz: No match' it failed. If it writes 'ld: No reference to __DYNAMIC' you have shareable versions of the zlib installed, which is good enough. Try appending -Bshareabale to the commands:

ld -L/usr/local/lib -lz -nostdlib -Bshareable
ld -L/usr/lib -lz -nostdlib -Bshareable

This way you know where your zlib is located. You need to know that. If both fails, you first need to install zlib. This is not covered in this how-to.

2. Check for jpeglib

Same thing as above, check where jpeglib is located:

ld -L/usr/local/lib -ljpeg -nostdlib 
ld -L/usr/lib -ljpeg -nostdlib 

If both fails you need to install jpeglib. That is not covered in this how-to either, but I should remind you to install the libs with make install-lib. A quick overview of how to install is this:

  ./configure
  make
  make install-lib

3. Make the Imaging lib:

Change to the libImaging directory in the Imaging-1.1.2 directory:

  cd libImaging

You need to run configure. Configure must be told where the image and zlib libraries are located. For the purpose of this how-to we will assume zlib is located in /usr/lib and jpeglib in /usr/local/lib

  ./configure --with-zlib=/usr/lib --with-jpeg=/usr/local/lib

Unfortunately, though this makes configure find the libraries, it doesn't write this into the makefile. So you need to do that. Edit Makefile so the LIBS= line reads like this:

  LIBS=           -L/usr/lib -lz -L/usr/local/lib -ljpeg  -lm

Then create the imaging lib:

  make

And finally test it:

./coretest

4. Check if you have TK or not.

[Test for this to be determined]

If not, edit Setup.in and comment out the lines concerning TK so they look like this:

#_imagingtk  _imagingtk.c \
#       -IlibImaging Tk/tkImaging.c \
#       -I/usr/local/include -L/usr/local/lib -ltcl8.0 -ltk8.0 \
#       -L/usr/X11R6/lib -lX11

5. Make the python _imaging module:

cd ..
make -f Makefile.pre.in boot
make

6. Test that things work:

python
import PIL.Image
a = PIL.Image.open('Images/lena.jpg')
a.load()
a.size

This should print out: (128, 128)

7. Install into Zope

cp -r PIL *.so /the/zope/installation/lib/python/

That should be it!