Neos\Neos\ViewHelpers\Backend\ColorOfStringViewHelper::render PHP Méthode

render() public méthode

Outputs a hex color code (#000000) based on $text
public render ( string $string = null, integer $minimalBrightness = 50 ) : string
$string string
$minimalBrightness integer
Résultat string
    public function render($string = null, $minimalBrightness = 50)
    {
        if ($minimalBrightness < 0 or $minimalBrightness > 255) {
            throw new \Exception('Minimal brightness should be between 0 and 255', 1417553921);
        }
        if ($string === null) {
            $string = $this->renderChildren();
        }
        $hash = md5($string);
        $rgbValues = array();
        for ($i = 0; $i < 3; $i++) {
            $rgbValues[$i] = max(array(round(hexdec(substr($hash, 10 * $i, 10)) / hexdec('FFFFFFFFFF') * 255), $minimalBrightness));
        }
        $output = '#';
        for ($i = 0; $i < 3; $i++) {
            $output .= str_pad(dechex($rgbValues[$i]), 2, 0, STR_PAD_LEFT);
        }
        return $output;
    }
ColorOfStringViewHelper