在Python中覆盖图像的文件名

时间:2013-09-07 20:26:18

标签: python python-imaging-library

我正在使用Python,我有以下代码片段:

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

来源:Add Text on Image using PIL

我遇到的问题是我无法将文件重命名为原文,有没有办法实现此目的?

回溯:

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'

0 个答案:

没有答案