Need to add a caption to a jpg, python can't find the image

importImage,ImageDraw,ImageFont, os, glob

list = glob.glob('*.jpg')for infile in list:print infile
file, ext = os.path.splitext(infile)
outname = file +"_test.jpg"print outname
im =Image.open(infile)
d =ImageDraw.Draw(im)
f =ImageFont.truetype("Arial.ttf",16)
d.text((4,0), file, font=f)
im.save(outname)

It prints out the name of the file, so the file is there - so why can't it open it?

The file exists, but I get the following error: Need to add a caption to a jpg, python can't find the image

Is there an easier way to add a caption to the bottom of the image?

Thanks to the help of Nick & Manu pointing me in the right dierction, I worked out a solution that works:


importImage,ImageDraw,ImageFontfrom PIL importImageimport glob, os
importTkinterimportImageTkimport fnmatch list = glob.glob('*.jpg') cnt =0for infile in list:
cnt +=1print infile
file, ext = os.path.splitext(infile)
outname = file +"_test.jpg"print outname
#im = Image.open(infile)
im =Image.open(open(infile,'rb'))
d =ImageDraw.Draw(im)
f =ImageFont.truetype("c:/windows/fonts/arial.ttf",200)
x =10
y =550
d.text((x, y), str(cnt), font=f)
im.save(outname)print"==========="
上一篇:centos7 下 apache nginx squid https正向代理 代理服务器


下一篇:26 个 jQuery使用技巧