嗨害大家好鸭!我是爱摸鱼的芝士❤
这次使用python代码来给照片
批量添加水印❤
添加水印逻辑
"""
为当指定目录下所有的图片文件添加水印
"""
import os
from PIL import Image
import PIL.PngImagePlugin
logo_filename = 'catlogo.png'
logo_img = Image.open(logo_filename)
target_dir = 'assets'
work_dir = target_dir + '_watermark'
if not os.path.exists(work_dir):
os.makedirs(work_dir)
for filename in os.listdir(target_dir):
if not (filename.endswith('.jpg') or filename.endswith('.png')) or filename == logo_filename:
continue
filename_load_path = os.path.join(target_dir, filename)
cat_img = Image.open(filename_load_path)
cat_img_width, cat_img_height = cat_img.size
logo_img_copy = logo_img.copy()
min_side = cat_img_width if cat_img_width < cat_img_height else cat_img_height
logo_img_copy = logo_img_copy.resize((int(min_side /