/**
* Add a gradient.
*
* @param \Pop\Color\Space\ColorInterface $color1
* @param \Pop\Color\Space\ColorInterface $color2
* @param int $type
* @return \Pop\Image\Svg
*/
public function addGradient(ColorInterface $color1, ColorInterface $color2, $type = Svg::HORIZONTAL)
{
$this->curGradient = count($this->gradients);
$defs = $this->resource->addChild('defs');
switch ($type) {
case self::HORIZONTAL:
$grad = $defs->addChild('linearGradient');
$grad->addAttribute('id', 'grad' . $this->curGradient);
$grad->addAttribute('x1', '0%');
$grad->addAttribute('y1', '0%');
$grad->addAttribute('x2', '100%');
$grad->addAttribute('y2', '0%');
break;
case self::VERTICAL:
$grad = $defs->addChild('linearGradient');
$grad->addAttribute('id', 'grad' . $this->curGradient);
$grad->addAttribute('x1', '0%');
$grad->addAttribute('y1', '0%');
$grad->addAttribute('x2', '0%');
$grad->addAttribute('y2', '100%');
break;
case self::RADIAL:
$grad = $defs->addChild('radialGradient');
$grad->addAttribute('id', 'grad' . $this->curGradient);
$grad->addAttribute('cx', '50%');
$grad->addAttribute('cy', '50%');
$grad->addAttribute('r', '50%');
$grad->addAttribute('fx', '50%');
$grad->addAttribute('fy', '50%');
break;
}
$stop1 = $grad->addChild('stop');
$stop1->addAttribute('offset', '0%');
$stop1->addAttribute('style', 'stop-color: ' . $color1->get(3, true) . '; stop-opacity: 1;');
$stop2 = $grad->addChild('stop');
$stop2->addAttribute('offset', '100%');
$stop2->addAttribute('style', 'stop-color: ' . $color2->get(3, true) . '; stop-opacity: 1;');
return $this;
}