Created
June 13, 2024 13:10
-
-
Save ftnext/162898df3011883380f89771b647adde to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /// script | |
# dependencies = ["Pillow"] | |
# /// | |
import argparse | |
from pathlib import Path | |
from PIL import Image | |
parser = argparse.ArgumentParser() | |
parser.add_argument("base_image", type=Path) | |
parser.add_argument("mask_image", type=Path) | |
parser.add_argument("output_image", type=Path) | |
args = parser.parse_args() | |
mask_image = Image.open(args.mask_image) | |
base_image = Image.open(args.base_image) | |
base_image.thumbnail(mask_image.size, Image.BICUBIC) | |
canvas_image = Image.new("RGB", mask_image.size, "white") | |
canvas_image.paste( | |
base_image, | |
( | |
(mask_image.size[0] - base_image.size[0]) // 2, | |
(mask_image.size[1] - base_image.size[1]) // 2, | |
), | |
) | |
canvas_image.paste(mask_image, mask=mask_image) | |
canvas_image.save(args.output_image) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment