#! /Usr/bin/env python #-*-Coding: UTF-8 -*- Import OS, sys, fnmatch Import Image, ImageDraw, ImageFont Def process_picture (filename ): Seq = OS. path. split (filename) [-1] [0]. upper () Img = Image. open (OS. path. join (input_dir, filename )) Draw = ImageDraw. Draw (img) # Draw a black circle in the bottom right corner Draw. ellipse (215,215,235,235), outline = 'black', fill = 'white ') # Write the letter number into the circle Font = ImageFont. truetype ('fonts/Times New Roman. ttf', 20) # Calculate the text Center Position Text_size = draw. textsize (seq, font) X = (20/2)-(text_size [0]/2) Y = (20/2)-(text_size [1]/2) # Letter offset Offsets = {'A': 1, 'B': 1, 'E': 1, 'D': 2} Offset = offsets. get (seq, 0) Draw. text (215 + x + offset, 215 + y), seq, font = font, fill = 'black ') # Save image Img. save (OS. path. join (output_dir, filename), 'jpeg ') If _ name _ = '_ main __': If len (sys. argv) <3: Print 'usage: python drawseq. py <input_dir> <output_dir>' Sys. exit (1) Input_dir, output_dir = sys. argv [1: 3] OS. path. exists (output_dir) or OS. makedirs (output_dir) For filename in OS. listdir (input_dir ): If fnmatch. fnmatch (filename. lower (), '*. jpg '): Process_picture (filename) |