1. Go to this page and download the library: Download aristath/ari-color library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
// Get red value:
$red = $color->red;
// Get green value:
$green = $color->green;
// Get blue value
$blue = $color->blue;
// Get hue
$hue = $color->hue;
// Get saturation
$saturation = $color->saturation;
// Get lightness
$lightness = $color->lightness;
// Get luminance
$luminance = $color->luminance;
/**
* determine the luminance of the given color
* and then return #FFFFFF or #222222 so that our text is always readable
*
* @param $background color string|array
*
* @return string (hex color)
*/
function custom_get_readable_color( $background_color = '#FFFFFF' ) {
$color = ariColor::newColor( $background_color );
return ( 127 < $color->luminance ) ? '#222222' : '#FFFFFF';
}
function my_theme_get_semitransparent_color( $color ) {
// Create the color object
$color_obj = ariColor::newColor( $color );
// Set alpha (opacity) to 0.7
$color_obj->alpha = 0.7;
// return a CSS-formated rgba color
return $color_obj->toCSS( 'rgba' );
}
// Create a new object using rgba as our original color
$color = ariColor::newColor( 'rgba(0, 33, 176, .62)' );
// Darken the color by 10%
$dark = $color->getNew( 'lightness', $color->lightness - 10 );
// return HEX color
return $dark->toCSS( 'hex' );
// Create a new color object using an HSL color as source
$color = ariColor::newColor( 'hsl(200, 33%, 82%)' );
// I don't like green, color, let's remove any traces of green from that color
$new_color = $color->getNew( 'green', 0 );
// Create our instance
$color = ariColor::newColor( 'hsl(200, 33%, 82%)' );
// Get HEX color
$hex = $color->toCSS( 'hex' );
// Get RGB color
$rgb = $color->toCSS( 'rgb' );
// Get RGBA color
$rgba = $color->toCSS( 'rgba' );
// Get HSL color
$hsl = $color->toCSS( 'hsl' );
// Get HSLA color
$hsla = $color->toCSS( 'hsla' );
/**
* Sanitizes a CSS color.
*
* @param $color string accepts all CSS-valid color formats
* @return string the sanitized color
*/
function custom_color_sanitize( $color = '' ) {
// If empty, return empty
if ( '' == $color ) {
return '';
}
// If transparent, return 'transparent'
if ( is_string( $color ) && 'transparent' == trim( $color ) ) {
return 'transparent';
}
// Instantiate the object
$color_obj = ariColor::newColor( $color );
// Return a CSS value, using the auto-detected mode
return $color_obj->toCSS( $color_obj->mode );
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.