A neat collection of useful methods to convert colors between different color spaces is available on GitHub call ColorConverter (MIT License). It can convert any values between RGB, HSL, CMYK, YUV and HEX colors.
I created a ready-to-use php class out of this method collection:
https://github.com/mixable/color-utils
Usage
The methods itself are mostly self-explaining. To use the class, just include the php file into your script and you are ready to go:
require('ColorUtils.php');
The methods itself are static, they can be used like:
$hex = '#ffcc00';
$rgb = ColorUtils::hex2rgb($hex);
Which results in an array with three values (red, blue, green) in $rgb
:
// [0 => 255, 1 => 204, 2 => 0]
Photo by Kelli Tungay on Unsplash
Leave a Reply