1. Go to this page and download the library: Download dustinwilson/pigmentum 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/ */
dustinwilson / pigmentum example snippets
class dW\Pigmentum\Color {
// Common illuminants used in color spaces
const ILLUMINANT_D65 = [ 0.95047, 1, 1.08883 ];
const ILLUMINANT_D50 = [ 0.96422, 1, 0.82521 ];
const REFERENCE_WHITE = self::ILLUMINANT_D50;
// Math constants
const KAPPA = 903.296296296296296;
const EPSILON = 0.008856451679036;
// RGB color profiles
const PROFILE_SRGB = 'dW\Pigmentum\Color\Profile\RGB\sRGB';
const PROFILE_SIMPLE_SRGB = 'dW\Pigmentum\Color\Profile\RGB\Simple_sRGB';
const PROFILE_ADOBERGB1998 = 'dW\Pigmentum\Color\Profile\RGB\AdobeRGB1998';
const PROFILE_PROPHOTORGB = 'dW\Pigmentum\Color\Profile\RGB\ProPhoto';
const PROFILE_DISPLAYP3 = 'dW\Pigmentum\Color\Profile\RGB\DisplayP3';
public ?string $name = null;
public static string $workingSpaceRGB = self::PROFILE_SRGB;
public static function withLab(float $L, float $a, float $b, ?string $name = null): dW\Pigmentum\Color;
public static function withLCHab(float $L, float $C, float $H, ?string $name = null): dW\Pigmentum\Color;
public static function withRGB(float $R, float $G, float $B, ?string $name = null, ?string $profile = null): dW\Pigmentum\Color;
public static function withRGBHex(string $hex, ?string $name = null, ?string $profile = null): dW\Pigmentum\Color;
public static function withHSB(float $H, float $S, float $B, ?string $name = null, ?string $profile = null): dW\Pigmentum\Color;
public static function withXYZ(float $X, float $Y, float $Z, string $name = null): dW\Pigmentum\Color;
public function toLab(): dW\Pigmentum\ColorSpace\Lab;
public function toRGB(?string $profile = null): dW\Pigmentum\ColorSpace\RGB;
public function toXYZ(): dW\Pigmentum\ColorSpace\XYZ;
public static function average(dW\Pigmentum\Color ...$colors): dW\Pigmentum\Color;
public static function averageWithLab(dW\Pigmentum\Color ...$colors): dW\Pigmentum\Color;
public static function averageWithLCHab(dW\Pigmentum\Color ...$colors): dW\Pigmentum\Color;
public static function averageWithRGB(dW\Pigmentum\Color ...$colors): dW\Pigmentum\Color;
public static function averageWithHSB(dW\Pigmentum\Color ...$colors): dW\Pigmentum\Color;
public function mix(dW\Pigmentum\Color $color, float $percentage = 0.5): dW\Pigmentum\Color;
public function mixWithLab(dW\Pigmentum\Color $color, float $percentage = 0.5): dW\Pigmentum\Color;
public function mixWithLCHab(dW\Pigmentum\Color $color, float $percentage = 0.5): dW\Pigmentum\Color;
public function mixWithRGB(dW\Pigmentum\Color $color, float $percentage = 0.5): dW\Pigmentum\Color;
public function mixWithHSB(dW\Pigmentum\Color $color, float $percentage = 0.5): dW\Pigmentum\Color;
public function apcaContrast(dW\Pigmentum\Color $backgroundColor): float;
public function deltaE(dW\Pigmentum\Color $color): float;
public function distance(dW\Pigmentum\Color $color): float;
public function euclideanDistance(dW\Pigmentum\Color $color): float;
public function wcag2Contrast(dW\Pigmentum\Color $color): float;
}
public static function withLab(
float $L,
float $a,
float $b,
?string $name = null
): dW\Pigmentum\Color;
class dW\Pigmentum\ColorSpace\Lab implements \Stringable {
public readonly float $L;
public readonly float $a;
public readonly float $b;
public function toLCHab(): dW\Pigmentum\ColorSpace\Lab\LCHab;
}
public function toLCHab(): dW\Pigmentum\ColorSpace\Lab\LCHab;
class dW\Pigmentum\ColorSpace\RGB implements \Stringable {
public readonly float $R;
public readonly float $G;
public readonly float $B;
public readonly float $unclampedR;
public readonly float $unclampedG;
public readonly float $unclampedB;
public readonly string $profile;
public readonly bool $outOfGamut;
public function changeProfile(?string $profile = null): dW\Pigmentum\ColorSpace\RGB;
public function convertToWorkingSpace(?string $profile = null): dW\Pigmentum\ColorSpace\RGB;
public function toHex(): string;
public function toHSB(): dW\Pigmentum\ColorSpace\RGB\HSB;
}
public function changeProfile(
?string $profile = null
): dW\Pigmentum\ColorSpace\RGB;
namespace dW\Pigmentum\Color;
// sRGB is the default working space
$color = Color::withRGBHex('#ca6e48');
echo $color->RGB . "\n";
echo $color->RGB->changeProfile(Color::PROFILE_DISPLAYP3);
class dW\Pigmentum\ColorSpace\XYZ implements \Stringable {
public function toLMS(): dW\Pigmentum\ColorSpace\XYZ\LMS;
public function chromaticAdaptation(array $new, array $old): dW\Pigmentum\ColorSpace\XYZ;
}
public function toLMS(): dW\Pigmentum\ColorSpace\XYZ\LMS;
class dW\Pigmentum\ColorSpace\Lab\LCHab implements \Stringable {
public readonly float $L;
public readonly float $C;
public readonly float $H;
}
class dW\Pigmentum\ColorSpace\RGB\HSB implements \Stringable {
public readonly float $H;
public readonly float $S;
public readonly float $B;
}
class dW\Pigmentum\ColorSpace\XYZ\LMS implements \Stringable {
public readonly float $rho;
public readonly float $gamma;
public readonly float $beta;
}
abstract class dW\Pigmentum\Profile\RGB {
const illuminant = dW\Pigmentum\Color::ILLUMINANT_D65;
const chromaticity = [];
const gamma = 2.2;
const name = '';
protected static array $xyzMatrix;
protected static array $xyzMatrixInverse;
public static function companding(float $channel): float;
public static function inverseCompanding(float $channel): float;
public static function getXYZMatrix(): MathPHP\LinearAlgebra\Matrix\Matrix;
}