from pathlib import Path from PIL import Image, ImageDraw, ImageFilter ROOT = Path(__file__).parent base_path = ROOT / "assets" / "advisor-training-worktable-wc-mug-clean.png" logo_path = ROOT / "assets" / "logo-mark-exact-transparent.png" out_path = ROOT / "assets" / "advisor-training-worktable-wc-mug-exact.png" base = Image.open(base_path).convert("RGBA") logo = Image.open(logo_path).convert("RGBA") # Mug face coordinates in the generated 1536x1024 image. # The patch covers the AI-rendered logo while preserving the mug's edge/handle. patch = Image.new("RGBA", base.size, (0, 0, 0, 0)) draw = ImageDraw.Draw(patch) ellipse_box = (1010, 350, 1162, 555) draw.ellipse(ellipse_box, fill=(246, 242, 232, 232)) patch = patch.filter(ImageFilter.GaussianBlur(1.2)) base = Image.alpha_composite(base, patch) # Prepare exact logo for the mug. We keep transparency and use high-quality scaling. logo_w = 104 ratio = logo_w / logo.width logo_h = int(logo.height * ratio) logo_resized = logo.resize((logo_w, logo_h), Image.Resampling.LANCZOS) # The logo sits on the visible front of the mug, centered over the patch. logo_x = 1034 logo_y = 382 base.alpha_composite(logo_resized, (logo_x, logo_y)) base.convert("RGB").save(out_path, quality=95) print(out_path)