Esempio n. 1
0
 /**
  * (non-PHPdoc)
  * @see Imagine\ImageInterface::crop()
  */
 public function crop(PointInterface $start, BoxInterface $size)
 {
     if (!$start->in($size)) {
         throw new OutOfBoundsException('Crop coordinates must start at minimum 0, 0 position from ' . 'top left corner, crop height and width must be positive ' . 'integers and must not exceed the current image borders');
     }
     try {
         $this->gmagick->cropimage($size->getWidth(), $size->getHeight(), $start->getX(), $start->getY());
     } catch (\GmagickException $e) {
         throw new RuntimeException('Crop operation failed', $e->getCode(), $e);
     }
     return $this;
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function crop(PointInterface $start, BoxInterface $size)
 {
     if (!$start->in($this->getSize())) {
         throw new OutOfBoundsException('Crop coordinates must start at minimum 0, 0 position from top left corner, crop height and width ' . 'must be positive integers and must not exceed the current image borders');
     }
     $this->fixViewBox();
     $svg = $this->document->documentElement;
     $svg->setAttribute('x', -$start->getX());
     $svg->setAttribute('y', -$start->getY());
     $svgWrap = $this->document->createElementNS('http://www.w3.org/2000/svg', 'svg');
     $svgWrap->setAttribute('version', '1.1');
     $svgWrap->setAttribute('width', $size->getWidth());
     $svgWrap->setAttribute('height', $size->getHeight());
     $svgWrap->appendChild($svg);
     $this->document->appendChild($svgWrap);
     return $this;
 }
Esempio n. 3
0
 /**
  * (non-PHPdoc)
  * @see Imagine\ImageInterface::crop()
  */
 public final function crop(PointInterface $start, BoxInterface $size)
 {
     if (!$start->in($this->getSize())) {
         throw new OutOfBoundsException('Crop coordinates must start at minimum 0, 0 position from ' . 'top  left corner, crop height and width must be positive ' . 'integers and must not exceed the current image borders');
     }
     $width = $size->getWidth();
     $height = $size->getHeight();
     $dest = imagecreatetruecolor($width, $height);
     imagealphablending($dest, false);
     imagesavealpha($dest, true);
     if (function_exists('imageantialias')) {
         imageantialias($dest, true);
     }
     if (false === imagecopymerge($dest, $this->resource, 0, 0, $start->getX(), $start->getY(), $width, $height, 100)) {
         throw new RuntimeException('Image crop operation failed');
     }
     imagedestroy($this->resource);
     $this->resource = $dest;
     return $this;
 }
Esempio n. 4
0
 /**
  * {@inheritdoc}
  */
 public function getColorAt(PointInterface $point)
 {
     if (!$point->in($this->getSize())) {
         throw new RuntimeException(sprintf('Error getting color at point [%s,%s]. The point must be inside the image of size [%s,%s]', $point->getX(), $point->getY(), $this->getSize()->getWidth(), $this->getSize()->getHeight()));
     }
     try {
         $pixel = $this->imagick->getImagePixelColor($point->getX(), $point->getY());
     } catch (\ImagickException $e) {
         throw new RuntimeException('Error while getting image pixel color', $e->getCode(), $e);
     }
     return $this->pixelToColor($pixel);
 }
Esempio n. 5
0
 /**
  * {@inheritdoc}
  */
 public function getColorAt(PointInterface $point)
 {
     if (!$point->in($this->getSize())) {
         throw new RuntimeException(sprintf('Error getting color at point [%s,%s]. The point must be inside the image of size [%s,%s]', $point->getX(), $point->getY(), $this->getSize()->getWidth(), $this->getSize()->getHeight()));
     }
     try {
         $cropped = clone $this->gmagick;
         $histogram = $cropped->cropImage(1, 1, $point->getX(), $point->getY())->getImageHistogram();
     } catch (\GmagickException $e) {
         throw new RuntimeException('Unable to get the pixel');
     }
     $pixel = array_shift($histogram);
     unset($histogram, $cropped);
     return $this->pixelToColor($pixel);
 }
Esempio n. 6
0
 /**
  * {@inheritdoc}
  */
 public function getColorAt(PointInterface $point)
 {
     if (!$point->in($this->getSize())) {
         throw new RuntimeException(sprintf('Error getting color at point [%s,%s]. The point must be inside the image of size [%s,%s]', $point->getX(), $point->getY(), $this->getSize()->getWidth(), $this->getSize()->getHeight()));
     }
     $pixel = $this->imagick->getImagePixelColor($point->getX(), $point->getY());
     return new Color(array($pixel->getColorValue(\Imagick::COLOR_RED) * 255, $pixel->getColorValue(\Imagick::COLOR_GREEN) * 255, $pixel->getColorValue(\Imagick::COLOR_BLUE) * 255), (int) round($pixel->getColorValue(\Imagick::COLOR_ALPHA) * 100));
 }
Esempio n. 7
0
 /**
  * {@inheritdoc}
  */
 public function getColorAt(PointInterface $point)
 {
     if (!$point->in($this->getSize())) {
         throw new RuntimeException(sprintf('Error getting color at point [%s,%s]. The point must be inside the image of size [%s,%s]', $point->getX(), $point->getY(), $this->getSize()->getWidth(), $this->getSize()->getHeight()));
     }
     $index = imagecolorat($this->resource, $point->getX(), $point->getY());
     $info = imagecolorsforindex($this->resource, $index);
     return new Color(array($info['red'], $info['green'], $info['blue']), (int) round($info['alpha'] / 127 * 100));
 }
 /**
  * (non-PHPdoc)
  * @see Imagine\Image\ImageInterface::getColorAt()
  */
 public function getColorAt(PointInterface $point)
 {
     if (!$point->in($this->getSize())) {
         throw new RuntimeException(sprintf('Error getting color at point [%s,%s]. The point must be inside the image of size [%s,%s]', $point->getX(), $point->getY(), $this->getSize()->getWidth(), $this->getSize()->getHeight()));
     }
     throw new RuntimeException('Not Implemented!');
 }