So I wanted to add captions to a set of images and wrote some lines of Python. Python has some cool image libraries so the job was real easy. Have never used Python before except to write some kindergarten-level programs, so this may not be the best way to code the thing. But it does the job.
import Image, ImageDraw, ImageFont, os
pathz="/home/thameera/ws/img_caption/pics"
if os.path.exists(pathz) and os.path.isdir(pathz):
for name in os.listdir(pathz):
print name
fullname=pathz+'/'+name
im = Image.open(fullname)
namez=name[:-4]
d = ImageDraw.Draw(im)
f = ImageFont.truetype("Arial.ttf", 16)
d.text((4,0), namez, font=f)
im.save(fullname)
else:
print "Directory not found"
It scans the given images directory and adds the file name sans extension as a caption, as shown below:
Original:will.i.am_1.jpg |
After adding the caption |
I’m curious. Why would you want to add the filename onto the image? In such an ugly font too.
Why should I tell you? I later edited the script with a better font and better positioning.
Why not tell me? 😛
Because I don’t feel like 😛
Bitch.