Skip to content

Add AI-powered semantic SVG recolorization#92

Draft
Copilot wants to merge 4 commits intomainfrom
copilot/improve-color-association-method
Draft

Add AI-powered semantic SVG recolorization#92
Copilot wants to merge 4 commits intomainfrom
copilot/improve-color-association-method

Conversation

Copy link

Copilot AI commented Feb 11, 2026

Current distance-based (CIEDE2000) color matching doesn't understand semantic roles—a logo's primary brand element and decorative background might map to the same palette if their colors are similar.

Changes

New AI mode (recolorizeSvgWithAI):

  • Analyzes SVG via AI vision APIs (OpenAI GPT-4o, Anthropic Claude, or custom)
  • Maps elements to semantic roles (primary-object, background, accent, etc.)
  • Assigns palettes based on conceptual meaning, not color distance
  • Falls back to distance-based on error

Enhanced recolorizeSvg:

  • Optional aiConfig parameter enables AI mode
  • Returns Promise<string> when using AI, string otherwise
  • Zero breaking changes—existing code unchanged

Providers supported:

  • OpenAI (gpt-4o)
  • Anthropic (claude-3-5-sonnet)
  • Custom endpoints

Example

// Before: distance-only (still default)
const result = recolorizeSvg(svg, palettes);

// Now: semantic understanding via AI
const result = await recolorizeSvg(svg, palettes, {
  aiConfig: {
    provider: "openai",
    apiKey: process.env.OPENAI_API_KEY,
  }
});

AI identifies elements by role, e.g.:

[
  {"selector": "circle[cx='50']", "role": "primary-object"},
  {"selector": "rect[width='200']", "role": "background"}
]

Maps to palettes: primary-object → primary, background → surface, accent → tertiary.

Implementation notes

  • Brightness-based tone selection within chosen palette
  • Automatic fallback prevents service disruption
  • 16 tests covering all providers and error paths
  • Docs: docs/AI_RECOLORIZATION.md, docs/MIGRATION_GUIDE.md

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits February 11, 2026 17:37
Co-authored-by: abernier <76580+abernier@users.noreply.github.com>
Co-authored-by: abernier <76580+abernier@users.noreply.github.com>
Co-authored-by: abernier <76580+abernier@users.noreply.github.com>
Copilot AI changed the title [WIP] Improve semantic color recolorization approach Add AI-powered semantic SVG recolorization Feb 11, 2026
Copilot AI requested a review from abernier February 11, 2026 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants