[Image-SIG] Re: Saving 12-bit grayscale from PIL

Fredrik Lundh fredrik@pythonware.com
Tue, 18 Sep 2001 08:33:10 +0200


Jonathan M. Gilligan wrote:

> I am using ActiveState Python 2.1 for Windows and PIL 1.1.1 (obtained using 
> the ActiveState package manager). When I try to save the image from PIL 
> using "img.save('foo.png','PNG')", where img is an Image.Image object, 
> python tells me, "C:\Python21\PIL\EpsImagePlugin.py:23: DeprecationWarning: 
> the regex module is deprecated; please use the re module import regex, 
> string" and then crashes python with an illegal memory access

Python 2.1 didn't exist when PIL 1.1.1 was released.  To get rid
of the warnings, use PIL 1.1.2.

> Here is a minimal script to reproduce the problem:

I doubt it qualifies as minimal when it requires more than
one extension library ;-)

Does this script work better:

import array
import Image

s = array.array("i", range(256*128)).tostring()

img = Image.fromstring('I', (256,128), s)
print img.size
print img.getpixel((255,0))
print img.getpixel((255,1))
print img.getpixel((0,127))
print img.getpixel((1,127))
print img.getpixel((255,127))

img.save('foo.png')

This works for me, with PIL 1.0 through 1.1.2 under Python 1.5.2
through 2.2a3 (all combinations I have on this machine).

If it works for you, your problem appears to be on the NumPy
side.  If it doesn't work for you, the problem appears to a broken
build.

You can get fresh binary builds from:

    http://www.pythonware.com/downloads/index.htm#pil

The 2.1.1 build should work (you have to move the files by hand
from c:\py21, though.  make sure you don't have any old PIL stuff
in the activestate tree)

> I would note, incidentally, that the PIL 1.1.1 source 
> (http://www.pythonware.com/downloads/Imaging-1.1.1.tar.gz) mixes whitespace 
> and tabs in many of the Imaging-1.1.1\PIL\*.py files. I don't think this 
> would be the source of the problems, but one never knows.

Oh, please.

</F>