#!/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.ellipse((215, 215, 235, 235), outline='black', fill='white')
# 将字母序号写入到圆圈内
font = ImageFont.truetype('fonts/Times New Roman.ttf', 20)
# 计算文字居中的位置
text_size = draw.textsize(seq, font)
x = (20 / 2) - (text_size[0] / 2)
y = (20 / 2) - (text_size[1] / 2)
# 字母偏移量
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)
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有