[Image-SIG] tif file save problem

Robert B. Klimek klimek@grc.nasa.gov
Thu, 31 Aug 2000 10:45:56 -0400


At 03:34 PM 8/31/00 +0200, you wrote:
>robert wrote:
>> I've come across a possible bug in PIL. There is something weird with .tif
>> or .bmp images that are saved by PIL. If you load a .tif image that was
>> previously saved by PIL and try to paste and image into it, it will crash
>> the program. Below is a test case from Idle but the same happens in my
>> python program. My OS is NT 4, sp 3.
>>
>> I'm using PIL 1.0. Is this fixed in PIL 1.1? Is there a fix?
>>
>>  >>> import Image
>>  >>> im = Image.open('c:\\Images\\im001.tif')
>>  >>> im.save('c:\\Images\\test1.tif')
>>  >>> im2 = Image.open('c:\\Images\\test1.tif')
>>  >>> roi = im2.crop((10,10,50,50))
>>  >>> im2.paste(roi,(10,10,50,50))
>>
>> The last line (paste) crashes the program and produces this error message.
>
>it's a known bug; PIL uses memory mapping for some file
>formats on Windows, and paste fails to realize that it has
>to "copy on write"...
>
>adding an explicit copy should fix this one:
>
>>  >>> im2 = Image.open('c:\\Images\\test1.tif')
>>  >>> im2 = im2.copy() # make sure we have a writable copy
>>  >>> roi = im2.crop((10,10,50,50))
>>  >>> im2.paste(roi,(10,10,50,50))

Fredrik,

That indeed does the trick. Thanks much!  The funny thing about it was that
it didn't do it with any other image files except the ones that PIL saved.

Another question for you. What are new features of PIL 1.1 compared to 1.0?
Is there a ducument somewhere that lists this?

Bob

-------------------------------------------------
Robert B. Klimek
NASA Glenn Research Center 
robert.klimek@grc.nasa.gov
(216) 433-2837
--------------------------------------------------