1. Go to this page and download the library: Download byteforge/color-randomizer 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/ */
byteforge / color-randomizer example snippets
use ByteForge\ColorRandomizer\ColorRandomizer;
// Example code...
// Generating a color without its name
$color = ColorRandomizer::getSingleColor(hex: true, minBrightness: 30, maxBrightness: 255, withMostMatchedName: false);
// Generating a color with its name
$color = ColorRandomizer::getSingleColor(hex: true, minBrightness: 30, maxBrightness: 255, withMostMatchedName: true, formattedName: true);
// 1st way
$colors = ColorRandomizer::getColors(formatNames: true); // You are able to Format Names through The function, This makes it better than the 2nd way.
// 2nd way
$colors = ColorRandomizer::$colors; // Color Names wont be formatted
// RGB To Hex
// 1st Way
$hex = ColorRandomizer::rgbToHex(fullRGB: "5, 91, 230"); // Make Sure You Specify The Argument Name Like 'fullRGB: $myRGB'. You can also give the RGB like rgb(5, 91, 230),
// Returns #055be6
// 2nd Way
$hex = ColorRandomizer::rgbToHex(r: 5, g: 91, b: 230); // Make Sure You Specify The Argument Name Like 'r:, g: and b:',
// Returns #055be6
// Hex To RGB
$rgb = ColorRandomizer::hexToRgb(hex: '#055be6');
// returns rgb(5, 91, 230)
// Get Color Difference Between 2 colors
$colorDifference = ColorRandomizer::colorDifference(color1: '#0548e6', color2: '#05a6e6', hex: true); // Hex refers that your color1 and color2 is Hex or RGB.
// returns 94. Similar Colors Threshold Could Be 130
// Get Color Brightness
$colorBrightness = ColorRandomizer::calculateBrightness(rgbOrHex: '#0548e6', type: 'hex'); // type must be hex or rgb, Its for verifying your Color code Type.
// returns 69
$colorName = ColorRandomizer::getNearestNameFromCode(hex: true, rgbOrHex: '#05e676'); // returns 'spring green'
// You can use ucwords($colorName) to format the words 1st letter to uppercase