Loading image...
--
--
Color HEX RGB HSL CMYK
Color Code
Color Code
Color Code
Color Code
Color Code

Color Picker API Integration Guide

A powerful client-side library for color analysis and manipulation. Learn how to integrate the Color Picker API into your projects.

Installation

1. Download the ColorPickerAPI:

2. Include the ColorPickerAPI script in your HTML file:

HTML
<script src="path/to/ColorPickerAPI.js"></script>

Basic Usage

1. Initialize the API

JavaScript
const colorPicker = new ColorPickerAPI();

2. Load Images

JavaScript
// From URL
const image = await colorPicker.loadImage('https://example.com/image.jpg');

// From File Input
const fileInput = document.querySelector('input[type="file"]');
const image = await colorPicker.loadImage(fileInput.files[0]);

// From Clipboard
const clipboardData = await navigator.clipboard.read();
const image = await colorPicker.loadImage(clipboardData[0]);

3. Extract Colors

JavaScript
const colors = await colorPicker.extractColors(image, {
    sampleSize: 10,      // Pixel sampling interval
    threshold: 60,       // Color similarity threshold
    maxClusters: 10,     // Maximum number of colors to extract
    minColorDistance: 30 // Minimum distance between distinct colors
});

4. Generate Color Variations

JavaScript
const baseColor = { r: 200, g: 50, b: 50 };

// Available variation types:
// 'opposite', 'adjacent', 'triadic', 'analogous', 'monochromatic'
const variations = colorPicker.getColorVariations(baseColor, 'analogous');

Advanced Features

Color Conversion

JavaScript
// RGB to HSL conversion
const { h, s, l } = colorPicker.rgbToHsl(200, 50, 50);

// HSL to RGB conversion
const { r, g, b } = colorPicker.hslToRgb(h, s, l);

Error Handling

JavaScript
try {
    const image = await colorPicker.loadImage('invalid-url');
} catch (error) {
    console.error('Failed to load image:', error);
}

Performance Optimization

  • The API uses Web Workers for color extraction to prevent UI blocking
  • Adjust sampleSize for balance between accuracy and performance
  • Use appropriate maxClusters value based on your needs
  • Consider image dimensions when setting sampling parameters

Browser Compatibility

  • Modern browsers (Chrome, Firefox, Safari, Edge)
  • Requires support for:
    • Web Workers
    • Canvas API
    • Promises
    • Async/Await

How to Use the Color Picker Tool

A powerful tool for extracting and analyzing colors from any image. Follow these simple steps to get started.

1. Loading Your Image

  • Choose from three convenient methods to load your image (max size: 10MB):
    • Upload from Device: Click the upload button or drag & drop an image file directly onto the canvas
    • Import from URL: Paste any public image URL from the web into the URL input field
    • Paste from Clipboard: Copy any image and use Ctrl+V (or click the paste area) to instantly load it
  • Supported image formats:
    • PNG, JPG, JPEG, GIF, WebP, and SVG
    • For best results, use images with clear, distinct colors

2. Using the Color Picker

  • Click anywhere on the loaded image to pick colors
  • Use the magnifier to see pixel-level details
  • Navigation Controls:
    • Mouse Wheel: Scroll to zoom in/out
    • Click and Drag: Pan around the image when zoomed
    • Mobile Touch: Pinch to zoom, two-finger pan
  • Click the Reset button to restore the original image view

3. Understanding Color Formats

  • View colors in multiple formats:
    • HEX: #RRGGBB format
    • RGB: Red, Green, Blue values
    • HSL: Hue, Saturation, Lightness
    • CMYK: Cyan, Magenta, Yellow, Key (Black)
  • Switch between format tabs to focus on specific color codes

4. Exporting Colors

  • Export your selected colors in three formats:
    • JSON: For developers and data processing
    • CSV: For spreadsheet applications
    • Text: Simple text format for quick use