Hello.
Problem:
When I try to save an opened Image object to a file that was previously created by Image.new() and saved, I have a permission denied error.
Steps to reproduce:
Environment:
Windows 7 (64-bits)
Python 2.7.3
Pillow 2.3.0
Execute the following code
from PIL import Image
img1 = Image.new('I;16', (10, 10))
img1.save('test.tiff', 'TIFF')
img2 = Image.open('test.tiff')
img2.save('test.tiff')
you should see this error
C:\Python27\lib\site-packages\PIL\Image.py
1458 if isPath(fp):
-> 1459 fp = builtins.open(fp, "wb")
1560 close = 1
1461 else:
IOError: [Errno 13] Permission denied: 'test.tiff'
Expected behavior:
It should save the image file, no matter how many references to that file I have.
Of course, I have permission to read/write the file inside the directory I am.
I executed it as Admin, I tried to change the mode from the line 1459 to "r+b", and the error is the same.
NOTE: On Ubuntu 12.04 LTS (same python and pillow versions) this code works well.
Thanks.
Hello.
I was trying to figure out the problem and I found a possible solution, at least it works for me:
Index: tags/2.3.0/PIL/Image.py
===================================================================
--- tags/2.3.0/PIL/Image.py (revision 1344)
+++ tags/2.3.0/PIL/Image.py (working copy)
@@ -1990,7 +1990,7 @@
if isPath(fp):
filename = fp
- fp = builtins.open(fp, "rb")
+ fp = builtins.open(fp, "r+b")
else:
filename = ""
Regards.
I'm not sure I understand the syntax change… @wiredfool ?
rb is open readonly + binary, r+b is read/write (aka update), binary.
I'm very -1 on setting Image.open to use overwrite mode. I think what's happening in the initial case is that image.tiff is still open, preventing the save. This almost sounds like #526, now that I look more closely.
Possible duplicate of #526
Yes, that's the problem, thanks.
when i use it , i only use the pathname, it needs a filename
Most helpful comment
Hello.
I was trying to figure out the problem and I found a possible solution, at least it works for me:
Regards.