#4 Changements + améliorations programme

This commit is contained in:
beren
2025-05-18 21:19:20 +02:00
parent c1bf873ca5
commit 9b3979ab7f
7 changed files with 526 additions and 160 deletions

View File

@ -2,6 +2,7 @@ from PIL import Image, ImageOps
import os
from pathlib import Path# main.py
import logging
import tempfile
logger = logging.getLogger(__name__)
logger.info("Logger from watermark")
@ -10,6 +11,7 @@ def create_watermark_image(image_path, filigrane_path="logo-lescreationsdemissbl
#image = Image.open(image_path).convert("RGBA")
image = ImageOps.exif_transpose(Image.open(image_path)).convert("RGBA")
filigrane = Image.open(filigrane_path).convert("RGBA")
temp_dir = tempfile.gettempdir()
# Resize the watermak (ex: 25% of widht from principal image)
"""ratio = 0.25
@ -30,16 +32,19 @@ def create_watermark_image(image_path, filigrane_path="logo-lescreationsdemissbl
# Paste watermark (with alpha mask)
image.paste(filigrane, (x, y), filigrane)
temp_image_path = os.path.join(temp_dir, image_path)
# Save the result
output_path = image_path.rsplit('.', 1)
output_path = f"{output_path[0]}-filigrane.jpg"
#output_path = image_path.rsplit('.', 1)
#output_path = f"{output_path[0]}.jpg"
output_path = os.path.basename(temp_image_path)
try:
if not os.path.exists(output_path):
image.convert("RGB").save(output_path, "JPEG")
except Exception as e:
logger.exception(f"🔥 Image avec filigrane existe déjà : {e} - {Path(output_path).name}")
print(f"outpath = {output_path}")
#print(f"outpath = {output_path}")
return output_path
#print(f"✅ Image enregistrée : {output_path}")