kachnitel/color-converter

Lightweight PHP library for color format conversion (hex, RGB, HSL) and luminance calculation

Installs: 2

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/kachnitel/color-converter

v0.0.1 2025-12-05 01:19 UTC

This package is not auto-updated.

Last update: 2025-12-05 02:08:16 UTC


README

Lightweight PHP library for color format conversion and luminance calculation.

Features

  • Convert hex colors to RGB
  • Convert hex colors to HSL
  • Determine if a color is light or dark based on luminance
  • Pure PHP with no dependencies
  • Fully tested

Installation

composer require kachnitel/color-converter

Usage

use Kachnitel\ColorConverter\ColorConverter;

$converter = new ColorConverter();

// Convert hex to RGB
$rgb = $converter->hex2rgb('#ff5733');
// ['r' => 255, 'g' => 87, 'b' => 51]

// Convert hex to HSL
$hsl = $converter->hex2hsl('#ff5733');
// ['h' => 11, 's' => 100, 'l' => 60]

// Check if color is light or dark
$isLight = $converter->isLight('#ff5733');
// false (dark color)

// Custom threshold for light/dark detection
$isLight = $converter->isLight('#ff5733', 70);
// true (with higher threshold)

Testing

composer install
vendor/bin/phpunit

License

MIT