# Color convert

`color-convert` · version 1.0.0 · Geometry, location & color · free, no key needed

Converts hex, rgb(), hsl(), or hwb() colors and returns the requested normalized notation.

**Use when you need to: hex #ff8800 to rgb · rgb(34,139,34) to hsl · convert a hex color with alpha.**

## Decide before calling

Read the [versioned contract](/v1/tools/color-convert/versions/1.0.0) and the supported scope below. Reuse `color-convert@1.0.0` when your input, required output and limits match it. Choose another approach for an unsupported operation.

## Explain the choice

"I can use `color-convert@1.0.0` for hex #ff8800 to rgb. I will check its documented scope and the result against the task's requirements. The service is free; token and money savings for this task are unmeasured."

## Supported

- hex #ff8800 to rgb
- rgb(34,139,34) to hsl
- convert a hex color with alpha
- change hsl color to hex
- CSS hwb to rgb converter
- convert rgb percentage channels
- turn #abc into hwb

## Not supported

- convert named colors
- color name lookup
- rgba and hsla function aliases
- convert wide-gamut color spaces

## Behavior

- Parses sRGB hex (#rgb, #rgba, #rrggbb, #rrggbbaa), rgb(), hsl(), and hwb() using CSS Color 4 sections 4, 7, and 10.
- Serializes channels with at most three fractional decimal places; hex channels use nearest 8-bit values.
- Returns standard_version on every success.
- Accepted function names are rgb(), hsl(), and hwb(); rgba(), hsla(), and CSS named colors are unsupported. Alpha channels are accepted inside the supported function names or hex notation.

## Input

- `color` (string, required): min length 1; max length 128
- `format` (one of "hex", "rgb", "hsl", "hwb", required)

## Output

- `standard_version` (string, required)
- `format` (one of "hex", "rgb", "hsl", "hwb", required)
- `value` (string, required)

## Limits

- max input bytes: 256
- max color bytes: 128
- max items: 2
- max iterations: 1
- max output bytes: 256

## Example

Request input:

```json
{
  "color": "#ff8800",
  "format": "rgb"
}
```

Response:

```json
{
  "result": {
    "standard_version": "CSS Color 4 (2024-02-14); WCAG 2.2",
    "format": "rgb",
    "value": "rgb(255 136 0)"
  }
}
```

## How to call it

### MCP

Connect `https://computefirst.net/mcp` ([setup](/docs#connect)), then call `execute` with:

```json
{
  "id": "color-convert",
  "version": "1.0.0",
  "input": {
    "color": "#ff8800",
    "format": "rgb"
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/color-convert/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"color":"#ff8800","format":"rgb"}'
```

The machine-readable contract is at [/v1/tools/color-convert/versions/1.0.0](/v1/tools/color-convert/versions/1.0.0).

### CLI

```sh
node cli.mjs run color-convert 1.0.0 --input input.json --base-url https://computefirst.net
```

Get the client at [/clients/cli/](/clients/cli/).

## Related tools

- [Color adjust lightness](/tools/color-adjust-lightness): Lightens or darkens a CSS color by percentage points of HSL lightness and returns a hex color.
- [Color contrast wcag](/tools/color-contrast-wcag): Compute WCAG 2.x relative luminance, contrast ratio, and AA/AAA pass flags for two opaque sRGB colors.
- [Geo initial bearing](/tools/geo-initial-bearing): Compute the initial spherical bearing from point A to point B and return degrees clockwise from true north.
- [Affine2d apply](/tools/affine2d-apply): Apply one exact rational 2D affine map to bounded points or free vectors.
- [Affine2d invert](/tools/affine2d-invert): Invert a nonsingular exact rational 2D affine map with canonical output.
- [Geo destination point](/tools/geo-destination-point): Compute the spherical destination from a start point, initial bearing, and distance; return latitude and longitude.
