Color Conversion
hexToRgb()
Parse a hex color string to RGB.Hex color string (e.g., “#ff8000” or “ff8000”)
RGB values as Uint8Array [r, g, b]
rgbToHex()
Convert RGB values to a hex color string.Red channel (0-255)
Green channel (0-255)
Blue channel (0-255)
Hex color string (e.g., “#ff8000”)
WCAG Color Analysis
relativeLuminance()
Calculate WCAG 2.x relative luminance for a hex color.Hex color string
Relative luminance value (0-1)
contrastRatio()
Calculate WCAG 2.x contrast ratio between two hex colors.First hex color string
Second hex color string
Contrast ratio (1.0-21.0)
- AA normal text: ratio ≥ 4.5
- AA large text: ratio ≥ 3.0
- AAA normal text: ratio ≥ 7.0
- AAA large text: ratio ≥ 4.5
Dominant Color
dominantRgbFromRgba()
Extract the dominant color from raw RGBA pixel data.Raw RGBA pixel data
Image width in pixels
Image height in pixels
Dominant RGB color as Uint8Array [r, g, b]
Readable Text Color
From the@iamkaf/kimg/color-utils subpath (pure JS, no WASM):
readableTextColor()
Determine whether black or white text is more readable on a given background color.Background hex color string
Either “#000000” (black) or “#ffffff” (white)
Base64 Helpers
From the@iamkaf/kimg/base64 subpath (pure JS, no WASM):
rgbaToBase64()
Encode RGBA pixel data as a base64 string.Raw RGBA pixel data
Base64-encoded string
base64ToRgba()
Decode a base64 string to RGBA pixel data.Base64-encoded string
Raw RGBA pixel data
Advanced Color Utilities
extractPaletteFromRgba()
Extract a color palette from raw RGBA pixel data.Raw RGBA pixel data
Image width in pixels
Image height in pixels
Maximum number of colors to extract
Flat RGBA palette data [r, g, b, a, r, g, b, a, …]
quantizeRgba()
Quantize raw RGBA pixel data to a specific palette.Raw RGBA pixel data
Image width in pixels
Image height in pixels
Flat RGBA palette data
Quantized RGBA pixel data
histogramRgba()
Compute a per-channel histogram for raw RGBA pixel data.Raw RGBA pixel data
Image width in pixels
Image height in pixels
Flat array of 1024 u32 values: r[0..256], g[256..512], b[512..768], a[768..1024]
Image Format Utilities
decodeImage()
Auto-detect and decode an image from bytes to raw RGBA pixel data.Image file bytes (supports PNG, JPEG, WebP, GIF)
Decoded RGBA pixel data (without width/height metadata)
The returned RGBA data does not include width/height information. Use
detectFormat() first if you need dimensions, or use the composition’s importImage() method instead.detectFormat()
Detect the image format from magic bytes.Image file bytes
Detected format: “png”, “jpeg”, “webp”, “gif”, “psd”, or “unknown”
WASM Runtime Utilities
simdSupported()
Check if the current environment supports WebAssembly SIMD (simd128).True if SIMD is supported and available
kimg automatically loads the appropriate WASM binary (baseline or SIMD) based on runtime support. This function is primarily useful for diagnostics and performance reporting.