Filigrana immagine
Aggiungi una filigrana di testo personalizzata con controllo su posizione, opacità e dimensione del carattere.
Domande Frequenti
Implementazione del Codice
from PIL import Image, ImageDraw, ImageFont
# Text watermark
def add_text_watermark(input_path, output_path, text, opacity=128):
base = Image.open(input_path).convert("RGBA")
layer = Image.new("RGBA", base.size, (0, 0, 0, 0))
draw = ImageDraw.Draw(layer)
try:
font = ImageFont.truetype("arial.ttf", size=40)
except:
font = ImageFont.load_default()
bbox = draw.textbbox((0, 0), text, font=font)
tw, th = bbox[2] - bbox[0], bbox[3] - bbox[1]
x = (base.width - tw) // 2
y = (base.height - th) // 2
draw.text((x, y), text, font=font, fill=(255, 255, 255, opacity))
watermarked = Image.alpha_composite(base, layer)
watermarked.convert("RGB").save(output_path)
add_text_watermark("input.jpg", "output.jpg", "© MyBrand")
# Image watermark (logo overlay)
def add_image_watermark(base_path, logo_path, output_path):
base = Image.open(base_path).convert("RGBA")
logo = Image.open(logo_path).convert("RGBA")
logo.thumbnail((base.width // 4, base.height // 4))
pos = (base.width - logo.width - 20, base.height - logo.height - 20)
base.paste(logo, pos, logo)
base.convert("RGB").save(output_path)Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.