0

我正在使用 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')

来源:使用 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'
4

0 回答 0