← back to Wallco Ai
colorway-variants.py: add --detect (two dominant tones) + --list-presets CLI modes for the preset-colorway endpoint
231021ed60e28ca025a265bc139c47a32f9ba525 · 2026-06-12 07:43:15 -0700 · Steve Abrams
Files touched
M scripts/colorway-variants.py
Diff
commit 231021ed60e28ca025a265bc139c47a32f9ba525
Author: Steve Abrams <steve@designerwallcoverings.com>
Date: Fri Jun 12 07:43:15 2026 -0700
colorway-variants.py: add --detect (two dominant tones) + --list-presets CLI modes for the preset-colorway endpoint
---
scripts/colorway-variants.py | 29 ++++++++++++++++++++++++++++-
1 file changed, 28 insertions(+), 1 deletion(-)
diff --git a/scripts/colorway-variants.py b/scripts/colorway-variants.py
index 023642e..32c974d 100755
--- a/scripts/colorway-variants.py
+++ b/scripts/colorway-variants.py
@@ -87,9 +87,36 @@ def recolor(im, src_ground_rgb, src_figure_rgb, dst_ground_rgb, dst_figure_rgb):
return out
+def rgb_to_hex(rgb):
+ return "#%02x%02x%02x" % (int(rgb[0]), int(rgb[1]), int(rgb[2]))
+
+
def main():
+ # --list-presets: dump COLORWAY_PAIRS as JSON (UI builds chips from this so
+ # the preset list lives in ONE place, not duplicated in server.js).
+ if len(sys.argv) >= 2 and sys.argv[1] == "--list-presets":
+ print(json.dumps({"ok": True, "presets": [
+ {"slug": s, "ground": g, "figure": f} for (s, g, f) in COLORWAY_PAIRS
+ ]}))
+ return
+ # --detect <input.png>: print the two dominant tones (ground=most-common,
+ # figure=less-common) as hex. The colorway-preset endpoint uses these as the
+ # ink_map `from` colors, then maps them to a preset's (ground,figure) `to`.
+ if len(sys.argv) >= 3 and sys.argv[1] == "--detect":
+ src_path = sys.argv[2]
+ if not os.path.exists(src_path):
+ print(json.dumps({"ok": False, "error": "file not found: %s" % src_path}))
+ sys.exit(2)
+ im = Image.open(src_path).convert("RGB")
+ two = detect_two_tones(im)
+ print(json.dumps({
+ "ok": True,
+ "ground_hex": rgb_to_hex(two[0][0]),
+ "figure_hex": rgb_to_hex(two[1][0]),
+ }))
+ return
if len(sys.argv) < 2:
- print("usage: colorway-variants.py <input.png>", file=sys.stderr)
+ print("usage: colorway-variants.py <input.png> | --detect <input.png> | --list-presets", file=sys.stderr)
sys.exit(1)
src_path = sys.argv[1]
if not os.path.exists(src_path):
← f7ada02 overnight-seam-loop: route DTD vote tally to stderr so it la
·
back to Wallco Ai
·
colorways: add preset-colorway endpoint (method 3) + LIMIT 1 62ff6da →