Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Color Laravel Package

spatie/color

PHP library for color parsing, conversion, and comparison. Supports CSS named colors plus RGB/RGBA/ARGB, Hex, HSL/HSLA, HSB, CMYK, CIELab, and XYZ. Includes WCAG contrast ratio and Delta E distances (CIE76, CIE94, CIEDE2000).

View on GitHub
Deep Wiki
Context7

A little library to deal with color conversions

Frequently asked questions about Color
How do I install spatie/color in a Laravel project?
Run `composer require spatie/color` in your Laravel project directory. The package has no Laravel-specific dependencies and works as a standalone PHP library. No additional configuration is needed for basic usage.
Which Laravel versions does spatie/color support?
spatie/color is framework-agnostic and works with any Laravel version compatible with its PHP requirements. As of the latest release, it supports PHP 8.1+, which aligns with Laravel 9+ and 10+. Test thoroughly if using older Laravel versions.
Can I use this package to validate WCAG contrast ratios for accessibility?
Yes, the package includes a `Contrast` class with a `ratio()` method to calculate WCAG contrast ratios between two colors. For example, `Contrast::ratio(Hex::fromString('#f0fff0'), Hex::fromString('#191970'))` returns the ratio value for compliance checks.
How do I convert a CSS color string (e.g., 'rgb(255, 0, 0)') to HEX format?
Use the `fromString()` factory method to parse the CSS string, then chain `toHex()`. Example: `$red = Color::fromString('rgb(255, 0, 0)')->toHex();` returns `#ff0000`. The library handles case-insensitive CSS named colors and standard formats.
Does spatie/color support CMYK or CIELab color spaces for print/web workflows?
Yes, the package supports CMYK, CIELab, and XYZ color spaces. Convert between formats using methods like `toCmyk()`, `toCIELab()`, or `toXyz()`. These are useful for print workflows, color-critical applications, or integrating with design tools.
How accurate are the Delta E (CIE76, CIE94, CIEDE2000) distance calculations?
The package implements standard Delta E algorithms for color difference measurement. CIEDE2000 is the most perceptually accurate for human vision, while CIE76 and CIE94 are faster but less precise. Use `Distance::CIEDE2000($color1, $color2)` for high-precision comparisons.
Can I use this package to dynamically generate Tailwind CSS or CSS variables?
Yes, the package’s stringable color objects work seamlessly with Tailwind’s `theme()` function or CSS variables. For example, store a color in a Blade template as `@php echo Color::fromHex('#3498db')->toCssVariable();` to generate `--color-primary: #3498db;` dynamically.
Are there performance concerns when processing thousands of colors in bulk?
The package is optimized for individual color operations but may not be ideal for bulk processing (e.g., >10K colors/sec). For high-throughput tasks, consider batching operations or exploring GPU-accelerated alternatives like ImageMagick or custom C extensions.
How do I handle invalid color inputs (e.g., malformed HEX strings) in production?
Wrap color parsing in a try-catch block to handle invalid inputs gracefully. Example: `try { $color = Color::fromHex($userInput); } catch (InvalidColorException $e) { log($e); return response()->json(['error' => 'Invalid color'], 400); }`. Always validate user-provided color values.
What alternatives exist if I need color blindness simulation or advanced ICC profiles?
spatie/color focuses on core conversions and comparisons. For color blindness simulation, consider integrating JavaScript libraries like [ColorBrewer](https://colorbrewer2.org/) or [Sim Daltonism](https://www.simdaltonism.com/) in the frontend. For ICC profiles, explore PHP libraries like `php-icc` or GPU-accelerated tools.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport