[Pythonmac-SIG] PIL on Mac doesn't work?

Clark Guest cguest@ucsd.edu
Fri, 19 Feb 1999 15:04:54 -0800


It appears that the _imaging shared library is not in your PATH. If you
haven't moved things around, use EditPythonPrefs to include:

$(PYTHON):Extensions:Imaging

and things should start to work. PIL is able to open (but not load) an
image file without the shared library, but needs it for anything else.

Of course, the next headache is that you can't display your image on the
Mac. The Image.show() method chokes. Assuming you're using the IDE, the
minimal code I've been able to use to see an image is:

import Wwindows
bnds = (100,100,356,356)
win = Wwindows.Window(bnds,"Test")
win.open()

import imgformat
import img
flnm ="yourFilePathHere.GIF"
rdr = img.reader(imgformat.macrgb16,flnm)
data = rdr.read()

import mac_image
pixmap = mac_image.mkpixmap(256,256,imgformat.macrgb16,data)

import Qd
import QuickDraw

Qd.CopyBits(pixmap,win.wid.GetWindowPort().portBits,(0,0,256,256),(0,0,256,256),
QuickDraw.srcCopy,None)

Notice:
a) That this is hardwired for a 256 x 256 image, for clarity of presentation.
b) It doesn't use PIL at all, but img instead. This is because img can read
directly into a macrgb16 format, but as far as I know, PIL cannot. It
should be possible to get PIL and img to talk to each other using PIL's
Image.tostring() and Image.fromstring() methods plus some math, but I
haven't worked out the details yet.
c) The resulting window doesn't refresh itself. See
$(PYTHON):Mac:Demo:imgbrowse:imgbrowse.py for some ideas on this. In the
meantime, re-execute the last line to refresh the image.

I have this vision of getting the IDE, Numeric, PIL, and a yet-to-be-named
(or written) plotting package working together as a seamless whole as a
python substitute for MatLab on the Mac. But I have precious little time to
work on it, so progress is glacial.

Hope this helps,
--Clark