python怎么添加标题_需要为jpg添加标题,python找不到imag

在尼克和马努的帮助下,我找到了一个可行的解决方案:import Image, ImageDraw, ImageFont

from PIL import Image

import glob, os

import Tkinter

import ImageTk

import fnmatch

list = glob.glob('*.jpg')

cnt = 0

for infile in list:

cnt += 1

print 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 "==========="

注意,这使用字体的直接路径,并且我设置了图像上的x,y位置。在

我还不得不使用一个非常大的字体大小,因为原始文件是一个非常大的完整图像从相机。在

我使用cnt作为一个字符串来保持连续性-原始文件有很多名称。在

我现在要做的就是找到图像的底部并将字符串放在那里。。。在


版权声明:本文为weixin_34643336原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。