pens

PHP ColorUtils

By

in

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:

PHP
require('ColorUtils.php');

The methods itself are static, they can be used like:

PHP
$hex = '#ffcc00';
$rgb = ColorUtils::hex2rgb($hex);

Which results in an array with three values (red, blue, green) in $rgb:

PHP
// [0 => 255, 1 => 204, 2 => 0]

Photo by Kelli Tungay on Unsplash



Comments

One response to “PHP ColorUtils”

  1. […] The used ColorUtils class above consists of methods that are used to convert colors between different color spaces. The library is available here. […]

Leave a Reply

Your email address will not be published. Required fields are marked *