Color Utilities

Get Luminance

Calculates relative luminance (0-1 brightness value) for any color input using the WCAG standard formula. Access via MCP in Cursor, Windsurf, and other AI editors, or call GET /v1/color/luminance directly. Pass hex (#FF0000), RGB (255,0,0), or named colors (red) to get precise luminance values essential for contrast ratio calculations and accessibility compliance.

API Endpoint

GET /v1/color/luminance

Code Examples

curl "https://tinyfn.io/v1/color/luminance" \
  -H "X-API-Key: YOUR_API_KEY"
const response = await fetch('https://tinyfn.io/v1/color/luminance', {
  headers: { 'X-API-Key': 'YOUR_API_KEY' }
});
const data = await response.json();
console.log(data);
import requests

response = requests.get('https://tinyfn.io/v1/color/luminance',
    headers={'X-API-Key': 'YOUR_API_KEY'})
data = response.json()
print(data)

Use via MCP

Add to your AI agent

Connect your AI agent (Claude, Cursor, Windsurf, etc.) to TinyFn's color tools:

{
  "mcpServers": {
    "tinyfn-color": {
      "url": "https://tinyfn.io/mcp/color",
      "headers": {
        "X-API-Key": "YOUR_API_KEY"
      }
    }
  }
}

Learn more about MCP setup →

FAQ

What is relative luminance and how is it calculated?

Relative luminance measures perceived brightness from 0 (black) to 1 (white) using the WCAG formula: 0.2126×R + 0.7152×G + 0.0722×B with gamma correction. It accounts for human eye sensitivity to different colors.

What color formats does the luminance API accept?

Accepts hex codes (#FF0000, #f00), RGB values (255,0,0 or rgb(255,0,0)), HSL format, and named colors (red, blue, etc.). Returns consistent decimal values regardless of input format.

How do I use luminance values for WCAG contrast compliance?

Calculate contrast ratio using (L1 + 0.05) / (L2 + 0.05) where L1 is the lighter color's luminance. WCAG AA requires 4.5:1 for normal text, 3:1 for large text.

Can MCP agents use this for automated accessibility testing?

Yes, AI agents in Cursor or Windsurf can call this tool to check color combinations in code, automatically flag contrast issues, and suggest compliant alternatives during development.

Why use this instead of calculating luminance myself?

Ensures WCAG-compliant calculations with proper gamma correction and sRGB handling. Eliminates common implementation errors in the complex luminance formula and supports multiple input formats.

Try Get Luminance Now

Get your free API key and start using Get Luminance in seconds.

Get Free API Key