[Image-SIG] tif file save problem

Fredrik Lundh fredrik@pythonware.com
Thu, 31 Aug 2000 15:34:04 +0200


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))

</F>

<!-- (the eff-bot guide to) the standard python library:
http://www.pythonware.com/people/fredrik/librarybook.htm
-->