from PIL import Image, ImageDraw, ImageFont
def add_watermark(image):
watermark_text = "AI Generated by DarkIdol FeiFei"
if not isinstance(image, Image.Image):
raise ValueError("Input must be a PIL Image object")
width, height = image.size
draw = ImageDraw.Draw(image)
font_size = 10
try:
font = ImageFont.truetype("Iansui-Regular.ttf", font_size)
except IOError:
font = ImageFont.load_default()
bbox = draw.textbbox((0, 0), watermark_text, font=font)
text_width = bbox[2] - bbox[0]
text_height = bbox[3] - bbox[1]
x = width - text_width - 10
y = height - text_height - 10
draw.text((x, y), watermark_text, font=font, fill=(255, 255, 255, 128))
return image