public function fromRgb(array $rgb) { $mode = 'rgb'; foreach ($rgb as $channel => $value) { if ($channel === 'a') { $value = Util\Color::constrainValue((string) $value, 0, 1); if ($value === 1) { continue; } $mode .= 'a'; } else { $value = Util\Color::normalizeRgbValue((string) $value); } $this->channels[$channel] = new Dimension($value); } $this->mode = $mode; return $this; }