Author: Nick Sagona, III (nick@popphp.org)
Example #1
0
 /**
  * Method to set the stroke color of paths in the PDF.
  *
  * @param  \Pop\Color\Space\ColorInterface $color
  * @return \Pop\Pdf\Pdf
  */
 public function setStrokeColor(ColorInterface $color)
 {
     $this->strokeColor = $color;
     $co_index = $this->getContentObject();
     $this->objects[$co_index]->setStream("\n" . $this->convertColor($color->getRed()) . " " . $this->convertColor($color->getGreen()) . " " . $this->convertColor($color->getBlue()) . " RG\n");
     return $this;
 }
Example #2
0
 /**
  * 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;
 }
Example #3
0
 /**
  * Method to colorize the image with the color passed.
  *
  * @param  \Pop\Color\Space\ColorInterface $color
  * @return \Pop\Image\Gd
  */
 public function colorize(ColorInterface $color)
 {
     // Create an image resource.
     $this->createResource();
     imagefilter($this->resource, IMG_FILTER_COLORIZE, $color->getRed(), $color->getGreen(), $color->getBlue());
     $this->output = $this->resource;
     return $this;
 }
Example #4
0
 /**
  * Set and return a color identifier.
  *
  * @param  \Pop\Color\Space\ColorInterface $color
  * @throws Exception
  * @return mixed
  */
 protected function setColor(ColorInterface $color = null)
 {
     $clr = null !== $color ? $color->get(3, true) : 'rgb(0,0,0)';
     return new \ImagickPixel($clr);
 }