|
2 | 2 | import shutil |
3 | 3 | import sys |
4 | 4 |
|
| 5 | +from PIL import Image |
5 | 6 | from sourcepp import vpkpp |
6 | 7 |
|
7 | 8 |
|
| 9 | +def add_overlay_to_image(base_path: str, overlay_path: str, out_path: str) -> None: |
| 10 | + base = Image.open(base_path).convert("RGBA") |
| 11 | + overlay = Image.open(overlay_path).convert("RGBA") |
| 12 | + base = base.resize(overlay.size, Image.Resampling.BICUBIC) |
| 13 | + base.paste(overlay, None, overlay) |
| 14 | + base.convert("RGB").save(out_path) |
| 15 | + |
| 16 | + |
8 | 17 | def build_addon(addon_dir: str, output_dir_parent: str) -> None: |
9 | 18 | output_dir = os.path.join(output_dir_parent, "p2ce_" + os.path.basename(addon_dir)) |
10 | 19 | os.makedirs(output_dir, exist_ok=True) |
@@ -34,6 +43,13 @@ def build_addon(addon_dir: str, output_dir_parent: str) -> None: |
34 | 43 | vpk.add_entry_from_file(os.path.basename(entry), entry) |
35 | 44 | vpk.bake() |
36 | 45 |
|
| 46 | + if ( |
| 47 | + os.path.exists(thumb_path := os.path.join(output_dir, ".assets", "thumb.png")) or |
| 48 | + os.path.exists(thumb_path := os.path.join(output_dir, ".assets", "thumb.jpg")) or |
| 49 | + os.path.exists(thumb_path := os.path.join(output_dir, ".assets", "thumb.jpeg")) |
| 50 | + ): |
| 51 | + add_overlay_to_image(thumb_path, os.path.join(os.path.dirname(__file__), "assets", "thumb_overlay.png"), thumb_path) |
| 52 | + |
37 | 53 |
|
38 | 54 | def zip_addons(parent_dir: str, stem: str) -> None: |
39 | 55 | print(f"Zipping contents of {parent_dir} into {stem}.zip") |
|
0 commit comments