SassColour::toString PHP Method

toString() public method

Converts the colour to a string.
public toString ( boolean $css3 = true ) : string
$css3 boolean whether to use CSS3 SVG1.0 colour names
return string the colour as a named colour, rgba(r,g,g,a) or #rrggbb
    public function toString($css3 = true)
    {
        $rgba = $this->getRgba();
        foreach ($rgba as $k => $v) {
            if (is_object($v)) {
                $rgba[$k] = $v->value;
            }
        }
        if ($rgba[3] < 1) {
            $rgba[3] = str_replace(',', '.', round($rgba[3], 2));
            return sprintf('rgba(%d, %d, %d, %s)', $rgba[0], $rgba[1], $rgba[2], $rgba[3]);
        } else {
            $colour = sprintf('#%02x%02x%02x', str_replace(',', '.', round($rgba[0])), str_replace(',', '.', round($rgba[1])), str_replace(',', '.', round($rgba[2])));
        }
        if ($css3) {
            if (empty(self::$_svgColours)) {
                self::$_svgColours = array_flip(self::$svgColours);
            }
            return array_key_exists($colour, self::$_svgColours) ? self::$_svgColours[$colour] : $colour;
        } else {
            return array_key_exists($colour, self::$_html4Colours) ? self::$_html4Colours[$colour] : $colour;
        }
    }