#! /usr/bin/python3
# vim: ts=8 sw=8 noexpandtab
# Usage: add data time water mark to image
import sys, os
import shutil
import time
from PIL import Image, ImageDraw, ImageFont
count = 0
def run(argv):
if len(argv) < 3:
print('Usage: %s folder|file target_folder [-y]' % argv[0])
return
do(argv[1], argv[2])
def do(source, dest):
if os.path.isdir(source):
for f in sorted(os.listdir(source)):
do(os.path.join(source, f), dest)
else: # file
try:
# get time string from filename
fname = os.path.splitext(os.path.basename(source))[0]
t = time.strptime(fname[:8], '%Y%m%d')
text = time.strftime('%Y.%m.%d', t)
if len(fname) >= 15:
t = time.strptime(fname[9:15], '%H%M%S')
text += time.strftime(' %H:%M:%S', t)
# add watermark
image = Image.open(source)
exif = None
if 'exif' in image.info:
exi
给照片加日期水印
最新推荐文章于 2023-01-18 17:01:18 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)