adopt: --holes passes through to cutout (enclosed black, e.g. bow strings)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
9
adopt.py
9
adopt.py
@@ -9,6 +9,7 @@ PictureBoxSizeMode.Zoom, so square keeps every icon the same visual size.
|
|||||||
py -3.12 adopt.py stat_health life_baby several
|
py -3.12 adopt.py stat_health life_baby several
|
||||||
py -3.12 adopt.py --all every name in the prompt list
|
py -3.12 adopt.py --all every name in the prompt list
|
||||||
py -3.12 adopt.py --size 512 hero larger square (default 128)
|
py -3.12 adopt.py --size 512 hero larger square (default 128)
|
||||||
|
py -3.12 adopt.py --holes archer also clear enclosed black (see cutout.py)
|
||||||
"""
|
"""
|
||||||
import glob
|
import glob
|
||||||
import importlib
|
import importlib
|
||||||
@@ -28,7 +29,7 @@ MARGIN = 0.04 # share of the side left free around the icon
|
|||||||
ALPHA_THRESHOLD = 8
|
ALPHA_THRESHOLD = 8
|
||||||
|
|
||||||
|
|
||||||
def adopt(name, size=None):
|
def adopt(name, size=None, holes=False):
|
||||||
size = size or SIZE
|
size = size or SIZE
|
||||||
raws = sorted(glob.glob(os.path.join(config.OUTPUT_DIR, f"{name}_raw_*.png")),
|
raws = sorted(glob.glob(os.path.join(config.OUTPUT_DIR, f"{name}_raw_*.png")),
|
||||||
key=os.path.getmtime)
|
key=os.path.getmtime)
|
||||||
@@ -36,7 +37,7 @@ def adopt(name, size=None):
|
|||||||
print(f" {name}: no raw render in output/, skipped")
|
print(f" {name}: no raw render in output/, skipped")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
image = cutout(raws[-1])
|
image = cutout(raws[-1], holes=holes)
|
||||||
box = image.getchannel("A").point(lambda v: 255 if v > ALPHA_THRESHOLD else 0).getbbox()
|
box = image.getchannel("A").point(lambda v: 255 if v > ALPHA_THRESHOLD else 0).getbbox()
|
||||||
if box is None:
|
if box is None:
|
||||||
print(f" {name}: fully transparent after cutout, skipped")
|
print(f" {name}: fully transparent after cutout, skipped")
|
||||||
@@ -76,6 +77,8 @@ def adopt_backdrop(name, width=1920, height=1080):
|
|||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
args = sys.argv[1:]
|
args = sys.argv[1:]
|
||||||
size = None
|
size = None
|
||||||
|
holes = "--holes" in args
|
||||||
|
args = [a for a in args if a != "--holes"]
|
||||||
if len(args) >= 2 and args[0] == "--size":
|
if len(args) >= 2 and args[0] == "--size":
|
||||||
size = int(args[1])
|
size = int(args[1])
|
||||||
args = args[2:]
|
args = args[2:]
|
||||||
@@ -87,5 +90,5 @@ if __name__ == "__main__":
|
|||||||
if args == ["--all"]:
|
if args == ["--all"]:
|
||||||
prompts = importlib.import_module(getattr(config, "PROMPTS_MODULE", "prompts_life"))
|
prompts = importlib.import_module(getattr(config, "PROMPTS_MODULE", "prompts_life"))
|
||||||
args = [p[0] for p in prompts.PROMPTS]
|
args = [p[0] for p in prompts.PROMPTS]
|
||||||
ok = sum(adopt(n, size) for n in args)
|
ok = sum(adopt(n, size, holes) for n in args)
|
||||||
print(f"{ok}/{len(args)} adopted")
|
print(f"{ok}/{len(args)} adopted")
|
||||||
|
|||||||
Reference in New Issue
Block a user