1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
from PIL import Image, ImageDraw, ImageFont import os
def add_text(img_path, text='svinda.github.io', show_result_image=False): img = Image.open(img_path) draw = ImageDraw.Draw(img) font = ImageFont.truetype('C:/windows/fonts/Arial.ttf', size=20) width, height = img.size draw.text((width - 150, height - 55), text, (14, 222, 111))
draw.text((width - 150, height - 35), text, (14, 222, 111, 0))
draw.text((width - 150, height - 75), text, (14, 222, 111), font=font) ImageDraw.Draw(img)
(path, suffix) = os.path.splitext(img_path) print(path, suffix) img.save(path + '_watermark.png') if show_result_image: img.show()
def add_text_all(img_paths=[], text='svinda.github.io', show_result_image=False): for img_path in img_paths: add_text(img_path, text, show_result_image)
if __name__ == '__main__': image_path = r"images\hexo-文章插入图片.png" add_text(image_path, 'svinda.github.io')
add_text_all([r"images\hexo-文章插入图片.png", r"images\hexo-文章插入图片 - 副本.png"])
|