import tkinter as tk
import win32api
import win32con
import pywintypes
from screeninfo import get_monitors
from PIL import Image, ImageDraw, ImageFont,ImageTk
font_family = "msyh.ttf" # Replace with your actual font filename
font_size = 36
def generate_watermark(text, width, height, color='#d5d5d5', opacity=10, lines=1, angle=0):
spacing = 10
# 创建一个 Image 对象,用于绘制水印
img = Image.new('RGBA', (width, height), (255, 255, 255, 0))
draw = ImageDraw.Draw(img)
font = ImageFont.truetype(font_family, font_size)
# 将文本拆分成多行
text_lines = text.split('\n')
# 计算每个水印的宽度和高度
bbox = draw.textbbox((0, 0), text_lines[0], font=font)
text_width, text_height = bbox[2] - bbox[0], bbox[3] - bbox[1] + 30
# 计算每行可以容纳的水印数量
watermarks_per_row = width // (text_width + spacing)
total_rows = (height - 50) // (text_height + spacing)
# 设置初始位置
x = 50
y = 50
for row in range(total_rows):
x = 50 # 每行重新从左侧开始
y = 50 + row * (text_height + spacing)
for col in range(watermarks_per_row):
# 旋转文本
rotated_text = Image.new('RGBA', (text_width, text_height), (255, 255, 255, 0))
rotated_draw = ImageDraw.Draw(rotated_text)
if row
我想实现全屏水印,但是只实现了一行。
对于计算,实在脑袋不够用,恳请各位赐教一下