0

I'm using Python and I have the following snippet of code:

>>> from PIL import Image
>>> from PIL import ImageFont
>>> from PIL import ImageDraw 
>>> img = Image.open("sample_in.jpg")
>>> draw = ImageDraw.Draw(img)
# font = ImageFont.truetype(<font-file>, <font-size>)
>>> font = ImageFont.truetype("sans-serif.ttf", 16)
# draw.text((x, y),"Sample Text",(r,g,b))
>>> draw.text((0, 0),"Sample Text",(255,255,255),font=font)
>>> img.save('sample_in.jpg')

source: Add Text on Image using PIL

The problem I am having is I can't rename the file the same as the original is there a way to accomplish this?

Traceback:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/PIL/Image.py", line 1433, in save
    fp = __builtin__.open(fp, "wb")
IOError: [Errno 13] Permission denied: 'sample_in.jpg'
Community
  • 1
  • 1
eWizardII
  • 1,916
  • 4
  • 32
  • 55
  • 1
    What do you mean "you can't rename the file the same as the original"? What happens? Do you get an error? If so, what error? Post the full traceback. – kindall Sep 07 '13 at 20:28
  • Thanks I have added the full traceback. – eWizardII Sep 07 '13 at 20:29
  • 2
    From your error, it seems to be a permissions error and nothing to do with python. Do you only have read-only permissions for your image? – Sajjan Singh Sep 07 '13 at 20:30
  • I think that must be the problem so I have this running on Raspberry Pi - basically on a Debian OS and I notice on the FTP the file permissions for those images were done as root, and not the Linux user which is what I am trying to make changes as. Let me see if I add this code back to the code that is run as root if that fixes my problem. – eWizardII Sep 07 '13 at 20:33
  • Thanks guys that was the issue - permissions! – eWizardII Sep 07 '13 at 20:36

0 Answers0