color_tools.naming
Color naming utilities for generating descriptive names from RGB values.
This module provides intelligent color naming that: - Matches exact CSS colors when possible - Identifies near matches to CSS colors - Generates descriptive names based on HSL properties - Avoids collisions with existing color names
- color_tools.naming.get_lightness_modifier(l)[source]
Get lightness modifier based on LAB L* value.
- Parameters:
l (
float) – LAB L* value (0-100)- Returns:
“very light”, “light”, “medium”, “dark”, “very dark”, or “”
- Return type:
Lightness modifier
- color_tools.naming.get_saturation_modifier(s, l)[source]
Get saturation modifier based on HSL saturation and lightness.
- color_tools.naming.get_hue_with_ish(h, s)[source]
Get “-ish” hue variant if near a boundary, otherwise None.
When a hue is within ±8° of a major hue boundary, we can describe it with an “-ish” modifier for more variety and precision.
- color_tools.naming.determine_base_hue(h, s, l)[source]
Determine base hue name including special cases and “-ish” variants.
Special cases like brown, pink, gold, etc. are determined by combinations of hue, saturation, and lightness.
When near hue boundaries (±8°), returns “-ish” variants for more descriptive names (e.g., “yellowish orange”, “reddish brown”).
- color_tools.naming.get_generic_hue(h)[source]
Get generic hue name from hue angle (fallback for collision avoidance).
This uses simple hue ranges without special cases like brown, teal, etc.
- color_tools.naming.is_unique_near_claim(rgb, css_name, palette_colors=None, threshold=5.0)[source]
Check if this RGB is the uniquely closest color to claim “near [css_name]”.
A color can only be named “near X” if no other color in the palette would also be within threshold distance to X.
- Parameters:
- Return type:
- Returns:
True if this is the unique closest color to css_name
- color_tools.naming.generate_color_name(rgb, palette_colors=None, near_threshold=5.0)[source]
Generate a descriptive name for an RGB color.
This function follows a priority-based naming strategy: 1. Exact match with CSS colors 2. Near match with CSS colors (within threshold, uniquely) 3. Generated descriptive name based on HSL properties
Generated names avoid collisions with CSS color names by falling back to generic hue names when necessary.
- Parameters:
- Returns:
name: Color name string
match_type: “exact”, “near”, or “generated”
- Return type:
Tuple of (name, match_type) where
Examples
>>> generate_color_name((255, 0, 0)) ('red', 'exact')
>>> generate_color_name((255, 10, 10)) ('near red', 'near')
>>> generate_color_name((128, 128, 255)) ('medium bright blue', 'generated')