RGBA Export Format
The RGBA exporter creates plaintext files with CSS-compatible RGBA color values.
Format Details
Section titled “Format Details”| Property | Value |
|---|---|
| Identifier | rgba |
| Extension | .txt |
| Use case | CSS, web development, alpha transparency |
Output Format
Section titled “Output Format”rgba(68, 1, 84, 255)rgba(72, 40, 120, 255)rgba(62, 73, 137, 255)rgba(49, 104, 142, 255)rgba(38, 130, 142, 255)rgba(31, 158, 137, 255)rgba(53, 183, 121, 255)rgba(110, 206, 88, 255)rgba(181, 222, 43, 255)rgba(253, 231, 37, 255)Each line contains RGBA values where R, G, B, and A are integers from 0-255.
CLI Usage
Section titled “CLI Usage”# Basic exportpalettize create viridis --format rgba --output colors.txt
# Specific number of colorspalettize create viridis -f rgba -o colors.txt --steps 10
# Print to stdoutpalettize create viridis -f rgba --steps 5Python Usage
Section titled “Python Usage”from palettize import create_colormap, get_scaler_by_name, get_exporter
cmap = create_colormap(preset="viridis")scaler = get_scaler_by_name("linear", domain_min=0, domain_max=1)exporter = get_exporter("rgba")
output = exporter.export( colormap=cmap, scaler=scaler, domain_min=0, domain_max=1, options={"num_colors": 10})
# Parse into usable formatimport recolors = []for line in output.strip().split('\n'): match = re.match(r'rgba\((\d+), (\d+), (\d+), (\d+)\)', line) if match: colors.append(tuple(map(int, match.groups())))
print(colors) # [(68, 1, 84, 255), (72, 40, 120, 255), ...]Options
Section titled “Options”| Option | Type | Default | Description |
|---|---|---|---|
num_colors | int | 256 | Number of colors to generate |
output_format | str | "css" | Output format (see below) |
alpha_format | str | "int" | Alpha format: "int" (0-255) or "float" (0-1) |
Output Formats
Section titled “Output Formats”| Format | Description | Example Output |
|---|---|---|
css | CSS rgba() format (default) | rgba(68, 1, 84, 255) |
tuple | Python tuple format | (68, 1, 84, 255) |
json | JSON array of arrays | [[68, 1, 84, 255], ...] |
Alpha Formats
Section titled “Alpha Formats”| Format | Description | Example |
|---|---|---|
int | Integer 0-255 (default) | rgba(68, 1, 84, 255) |
float | Float 0-1 | rgba(68, 1, 84, 1.0) |
CLI Examples
Section titled “CLI Examples”# Default CSS formatpalettize create viridis -f rgba --steps 5
# JSON array formatpalettize create viridis -f rgba --steps 5 -O output_format=json
# CSS with float alpha (standard CSS format)palettize create viridis -f rgba --steps 5 -O alpha_format=float
# Python tuple formatpalettize create viridis -f rgba --steps 5 -O output_format=tuplePython Examples
Section titled “Python Examples”from palettize import create_colormap, get_scaler_by_name, get_exporterimport json
cmap = create_colormap(preset="viridis")scaler = get_scaler_by_name("linear", domain_min=0, domain_max=1)exporter = get_exporter("rgba")
# JSON format - easy to parsejson_output = exporter.export( cmap, scaler, 0, 1, options={"num_colors": 5, "output_format": "json"})colors = json.loads(json_output)# [[68, 1, 84, 255], [59, 82, 139, 255], ...]
# CSS format with float alphacss_output = exporter.export( cmap, scaler, 0, 1, options={"num_colors": 5, "alpha_format": "float"})# rgba(68, 1, 84, 1.0)# rgba(59, 82, 139, 1.0)# ...Use Cases
Section titled “Use Cases”CSS Stylesheets
Section titled “CSS Stylesheets”.gradient { background: linear-gradient( to right, rgba(68, 1, 84, 255), rgba(49, 104, 142, 255), rgba(253, 231, 37, 255) );}Semi-transparent Colors
Section titled “Semi-transparent Colors”The RGBA format preserves alpha values, useful for overlays:
.overlay { background-color: rgba(68, 1, 84, 128); /* 50% opacity */}JavaScript Arrays
Section titled “JavaScript Arrays”const colors = [ 'rgba(68, 1, 84, 255)', 'rgba(72, 40, 120, 255)', 'rgba(62, 73, 137, 255)'];
// Use with Canvasconst ctx = canvas.getContext('2d');ctx.fillStyle = colors[0];Python Image Processing
Section titled “Python Image Processing”from PIL import Imageimport re
# Parse RGBA outputoutput = exporter.export(cmap, scaler, 0, 1, {"num_colors": 256})colors = []for line in output.strip().split('\n'): match = re.match(r'rgba\((\d+), (\d+), (\d+), (\d+)\)', line) if match: colors.append(tuple(map(int, match.groups())))
# Create a palette imagewidth, height = 256, 50img = Image.new('RGBA', (width, height))for x in range(width): for y in range(height): img.putpixel((x, y), colors[x])img.save('colorbar.png')Data Visualization Libraries
Section titled “Data Visualization Libraries”# Plotlyimport plotly.express as px
colors_css = output.strip().split('\n')fig = px.scatter(df, x='x', y='y', color='value', color_continuous_scale=colors_css)Alpha Channel
Section titled “Alpha Channel”Unlike the Hex format, RGBA includes the alpha channel:
- Fully opaque:
rgba(68, 1, 84, 255) - 50% transparent:
rgba(68, 1, 84, 128) - Fully transparent:
rgba(68, 1, 84, 0)
By default, Palettize colormaps are fully opaque (alpha=255).
Converting to CSS rgba() with Normalized Alpha
Section titled “Converting to CSS rgba() with Normalized Alpha”CSS rgba() typically uses alpha from 0-1, not 0-255. To convert:
def to_css_rgba(rgba_string): match = re.match(r'rgba\((\d+), (\d+), (\d+), (\d+)\)', rgba_string) if match: r, g, b, a = map(int, match.groups()) return f'rgba({r}, {g}, {b}, {a/255:.2f})' return rgba_string
# rgba(68, 1, 84, 255) -> rgba(68, 1, 84, 1.00)