Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:AI Builder Club Skills match style from image

From Leeroopedia
Knowledge Sources
Domains Image_Analysis, Video_Processing
Last Updated 2026-10-24 00:00 GMT

Overview

Concrete tool for analyzing a reference caption screenshot and generating a matching ASS style configuration, provided by the karaoke-captions skill.

Description

The match_style_from_image.py script analyzes a reference screenshot (e.g. a TikTok/YouTube caption frame) using Pillow and NumPy pixel analysis to detect highlight colors, primary text colors, and outline/shadow properties. It quantizes common viral caption colors (neon green, yellow, cyan) and emits a style.json file compatible with gen_ass. Optionally calibrates resolution and font size against a target video via ffprobe.

Usage

Run this script when you want to match the visual style of an existing caption screenshot rather than hand-authoring a style JSON. Alternatively, use a preset JSON directly (see presets/style.json or presets/yellow.json).

Code Reference

Source Location

Signature

def analyze_image(img_path: str) -> dict:
    """Analyze a reference screenshot and return a style configuration.

    Detects:
    - Highlight color: high-saturation (>0.6), bright (>120) pixels →
      quantized to neon-green/yellow/cyan or custom RGB→ASS
    - Primary color: white mask (>220 all channels) → white ASS
    - Outline/shadow: black stroke defaults (width=6, offset=8, blur=7)

    Returns a dict with keys:
        play_res_x, play_res_y, font, font_size, bold,
        primary_color, highlight_color, outline_color,
        outline, shadow, blur, soft_shadow,
        alignment, margin_v, uppercase,
        max_words_per_line, max_gap, break_on_punctuation
    """

def rgb_to_ass(r: int, g: int, b: int, a: int = 0) -> str:
    """Convert RGB to ASS color string &HAABBGGRR."""

def main():
    """CLI entry point.

    Args (via argparse):
        image: str   - Path to reference screenshot (PNG)
        output: str  - Output style JSON path (default: "style.json")
        --video: str - Target video for resolution calibration (optional)
    """

Import

# Run as CLI script:
# python match_style_from_image.py reference.png [output_style.json] [--video target.mp4]

# Or import the analysis function:
from match_style_from_image import analyze_image, rgb_to_ass
style = analyze_image("reference.png")

I/O Contract

Inputs

Name Type Required Description
image str (file path) Yes Reference screenshot image (PNG)
output str (file path) No Output style JSON path (default: style.json)
--video str (file path) No Target video for resolution calibration via ffprobe

Outputs

Name Type Description
style.json JSON file Style configuration dict with 18 keys (play_res_x, play_res_y, font, font_size, colors, outline, shadow, layout, grouping)

Usage Examples

Auto-Match From Screenshot

# Analyze a reference screenshot and generate style.json
python match_style_from_image.py reference_caption.png style.json

# Output:
# Detected style written -> style.json
#   Font: Montserrat Black
#   Primary Color: &H00FFFFFF
#   Highlight Color: &H0000FF00
#   Outline: 6, Soft Shadow: True

With Video Resolution Calibration

# Calibrate resolution and font size for a 720p video
python match_style_from_image.py reference.png style.json --video input.mp4

# Automatically scales: font_size=64, outline=4, shadow=5, margin_v=60 for 720p

Using a Preset Instead

# Skip image analysis; use a preset JSON directly
cp skills/karaoke-captions/presets/style.json ./style.json   # neon green, 720p
cp skills/karaoke-captions/presets/yellow.json ./style.json  # yellow highlight

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment