Pop\Color\Convert::toHex PHP Method

toHex() public static method

Method to convert a color space object to a hex RGB object
public static toHex ( Pop\Color\Space\ColorInterface $color ) : Hex
$color Pop\Color\Space\ColorInterface
return Pop\Color\Space\Hex
    public static function toHex(Space\ColorInterface $color)
    {
        $class = get_class($color);
        if ($class == 'Pop\\Color\\Space\\Hex') {
            throw new Exception('That color space object is already that type.');
        }
        $type = strtolower(substr($class, strrpos($class, '\\') + 1));
        $method = $type . 'ToHex';
        return self::$method($color);
    }

Usage Example

Example #1
0
 public function testLabToHex()
 {
     $hex = Convert::toHex(new Lab(100, 100, 100));
     $this->assertInstanceOf('Pop\\Color\\Space\\Hex', $hex);
     $this->assertEquals('#c39231', (string) $hex);
 }