Ejemplo n.º 1
1
 /**
  * @param $parameters
  * @param \Imagine\Image\BoxInterface $size
  *
  * @return array
  */
 protected function getHeightWidth($parameters, $size)
 {
     $newWidth = $parameters['x'];
     $newHeight = $parameters['y'];
     // retina x2
     if ($parameters['retina']) {
         $newWidth = $parameters['x'] * 2;
         $newHeight = $parameters['x'] * 2;
     }
     // calculate height when not set
     if (!$newHeight) {
         $newHeight = $size->getHeight() / $size->getWidth() * $newWidth;
     }
     // calculate width when not set
     if (!$newWidth) {
         $newWidth = $size->getWidth() / $size->getHeight() * $newHeight;
     }
     // if image is smaller keep ratio
     // e.g. when a square image is requested (200x200) and the original image is smaller (150x100)
     //      it still returns a squared image (100x100)
     if ($parameters['forceRatio']) {
         if ($newWidth > $size->getWidth()) {
             list($newHeight, $newWidth) = $this->getSizeInSameRatio($newHeight, $newWidth, $size->getWidth());
         }
         if ($newHeight > $size->getHeight()) {
             list($newWidth, $newHeight) = $this->getSizeInSameRatio($newWidth, $newHeight, $size->getHeight());
         }
     }
     return [$newWidth, $newHeight];
 }
Ejemplo n.º 2
0
 public function create(BoxInterface $size, ColorInterface $color = null)
 {
     $width = $size->getWidth();
     $height = $size->getHeight();
     if ($color === null) {
         $palette = self::$rgb;
         $color = '#ffffff';
         $alpha = 0;
     } else {
         $palette = $color->getPalette();
         $alpha = $color->getAlpha() / 100;
     }
     try {
         $pixel = new \GmagickPixel((string) $color);
         $pixel->setcolorvalue(\Gmagick::COLOR_OPACITY, $alpha);
         // does nothing as of Gmagick 1.1.7RC2.  Background will be fully opaque.
         $magick = new \Gmagick();
         $magick->newimage($width, $height, $pixel->getcolor(false));
         $magick->setimagecolorspace(\Gmagick::COLORSPACE_TRANSPARENT);
         $magick->setimagebackgroundcolor($pixel);
         return new RImage($magick, $palette, self::$emptyBag, array($width, $height));
     } catch (\Exception $e) {
         throw new \Imagine\Exception\RuntimeException("Gmagick: could not create empty image. {$e->getMessage()}", $e->getCode(), $e);
     }
 }
Ejemplo n.º 3
0
    /**
     * (non-PHPdoc)
     * @see Imagine\Image\ImagineInterface::create()
     */
    public function create(BoxInterface $size, Color $color = null)
    {
        $width  = $size->getWidth();
        $height = $size->getHeight();

        $color = null !== $color ? $color : new Color('fff');

        try {
            $pixel = new \ImagickPixel((string) $color);
            $pixel->setColorValue(
                \Imagick::COLOR_OPACITY,
                number_format(abs(round($color->getAlpha() / 100, 1)), 1)
            );

            $imagick = new \Imagick();
            $imagick->newImage($width, $height, $pixel);
            $imagick->setImageMatte(true);
            $imagick->setImageBackgroundColor($pixel);

            $pixel->clear();
            $pixel->destroy();

            return new Image($imagick);
        } catch (\ImagickException $e) {
            throw new RuntimeException(
                'Could not create empty image', $e->getCode(), $e
            );
        }
    }
 /**
  * {@inheritdoc}
  */
 public function apply(ImageInterface $image)
 {
     $currentSize = $image->getSize();
     $ratioCurrent = $currentSize->getHeight() / $currentSize->getWidth();
     $ratioNew = $this->size->getHeight() / $this->size->getWidth();
     // ratio inverse of original and thumb image
     $ratioInverseNew = 1 / $ratioNew;
     // image has to crop
     if ($ratioCurrent != $ratioNew) {
         if ($this->size->getWidth() > $this->size->getHeight()) {
             $cropHeight = $currentSize->getWidth() * $ratioNew;
             $cropWidth = $currentSize->getWidth();
             if ($cropHeight > $currentSize->getHeight()) {
                 $correction = 1 / ($cropHeight / $currentSize->getHeight());
                 $cropWidth *= $correction;
                 $cropHeight *= $correction;
             }
         } else {
             $cropWidth = $currentSize->getHeight() * $ratioInverseNew;
             $cropHeight = $currentSize->getHeight();
             if ($cropWidth > $currentSize->getWidth()) {
                 $correction = 1 / ($cropWidth / $currentSize->getWidth());
                 $cropWidth *= $correction;
                 $cropHeight *= $correction;
             }
         }
         $cropSize = new Box($cropWidth, $cropHeight);
         $startPoint = $this->gravity->getStartPoint($cropSize);
         $image = $image->crop($startPoint, $cropSize);
     }
     return $image->resize($this->size);
 }
Ejemplo n.º 5
0
 /**
  * (non-PHPdoc)
  * @see Imagine\Image\ImagineInterface::create()
  */
 public function create(BoxInterface $size, Color $color = null)
 {
     $width = $size->getWidth();
     $height = $size->getHeight();
     $resource = imagecreatetruecolor($width, $height);
     if (false === $resource) {
         throw new RuntimeException('Create operation failed');
     }
     $color = $color ? $color : new Color('fff');
     if (false === imagealphablending($resource, false) || false === imagesavealpha($resource, true)) {
         throw new RuntimeException('Could not set alphablending, savealpha and antialias values');
     }
     if (function_exists('imageantialias')) {
         imageantialias($resource, true);
     }
     $index = imagecolorallocatealpha($resource, $color->getRed(), $color->getGreen(), $color->getBlue(), round(127 * $color->getAlpha() / 100));
     if (false === $index) {
         throw new RuntimeException('Unable to allocate color');
     }
     if (false === imagefill($resource, 0, 0, $index)) {
         throw new RuntimeException('Could not set background color fill');
     }
     if ($color->getAlpha() >= 95) {
         imagecolortransparent($resource, $index);
     }
     return new Image($resource, $this);
 }
Ejemplo n.º 6
0
 /**
  * {@inheritdoc}
  */
 public function create(BoxInterface $size, ColorInterface $color = null)
 {
     $width = $size->getWidth();
     $height = $size->getHeight();
     $resource = imagecreatetruecolor($width, $height);
     if (false === $resource) {
         throw new RuntimeException('Create operation failed');
     }
     $palette = null !== $color ? $color->getPalette() : new RGB();
     $color = $color ? $color : $palette->color('fff');
     if (!$color instanceof RGBColor) {
         throw new InvalidArgumentException('GD driver only supports RGB colors');
     }
     $index = imagecolorallocatealpha($resource, $color->getRed(), $color->getGreen(), $color->getBlue(), round(127 * $color->getAlpha() / 100));
     if (false === $index) {
         throw new RuntimeException('Unable to allocate color');
     }
     if (false === imagefill($resource, 0, 0, $index)) {
         throw new RuntimeException('Could not set background color fill');
     }
     if ($color->getAlpha() >= 95) {
         imagecolortransparent($resource, $index);
     }
     return $this->wrap($resource, $palette);
 }
Ejemplo n.º 7
0
 /**
  * {@inheritdoc}
  */
 public function create(BoxInterface $size, ColorInterface $color = null)
 {
     $width = $size->getWidth();
     $height = $size->getHeight();
     $palette = null !== $color ? $color->getPalette() : new RGB();
     $color = null !== $color ? $color : $palette->color('fff');
     try {
         $gmagick = new \Gmagick();
         // Gmagick does not support creation of CMYK GmagickPixel
         // see https://bugs.php.net/bug.php?id=64466
         if ($color instanceof CMYKColor) {
             $switchPalette = $palette;
             $palette = new RGB();
             $pixel = new \GmagickPixel($palette->color((string) $color));
         } else {
             $switchPalette = null;
             $pixel = new \GmagickPixel((string) $color);
         }
         if ($color->getPalette()->supportsAlpha() && $color->getAlpha() < 100) {
             throw new NotSupportedException('alpha transparency is not supported');
         }
         $gmagick->newimage($width, $height, $pixel->getcolor(false));
         $gmagick->setimagecolorspace(\Gmagick::COLORSPACE_TRANSPARENT);
         $gmagick->setimagebackgroundcolor($pixel);
         $image = new Image($gmagick, $palette, new MetadataBag());
         if ($switchPalette) {
             $image->usePalette($switchPalette);
         }
         return $image;
     } catch (\GmagickException $e) {
         throw new RuntimeException('Could not create empty image', $e->getCode(), $e);
     }
 }
Ejemplo n.º 8
0
 /**
  * Modifies $width or $height (if one of them is empty) based on $box ratio.
  * @param number|null $width Desired width
  * @param number|null $height Desired height
  * @param \Imagine\Image\BoxInterface $box Original box for a reference
  */
 public static function scaleSize(&$width, &$height, \Imagine\Image\BoxInterface $box)
 {
     if (!$width || !$height) {
         $r = $box->getWidth() / $box->getHeight();
         if ($width) {
             $height = floor($width / $r);
         } else {
             $width = floor($height * $r);
         }
     }
 }
Ejemplo n.º 9
0
 /**
  * @param BoxInterface $imageSize
  * @param array $settings
  * @return array|mixed
  */
 private function calculateRatio(BoxInterface $imageSize, array $settings)
 {
     $ratio = array();
     if ($settings['height']) {
         $ratio[] = $settings['height'] / $imageSize->getHeight();
     }
     if ($settings['width']) {
         $ratio[] = $settings['width'] / $imageSize->getWidth();
     }
     $ratio = max($ratio);
     return $ratio;
 }
Ejemplo n.º 10
0
 public function crop(PointInterface $start, BoxInterface $size)
 {
     if ($this->image === null) {
         $this->load();
     }
     $width = $size->getWidth();
     $height = $size->getHeight();
     try {
         $this->image->getGmagick()->cropimage($width, $height, $start->getX(), $start->getY());
     } catch (\GmagickException $e) {
         throw new \Imagine\Exception\RuntimeException("Gmagick: Crop operation failed. {$e->getMessage()}", $e->getCode(), $e);
     }
     $this->size = array($width, $height);
     return $this;
 }
 /**
  * @covers \Imagine\Filter\Advanced\Grayscale::apply
  *
  * @dataProvider getDataSet
  *
  * @param \Imagine\Image\BoxInterface $size
  * @param \Imagine\Image\Color $color
  * @param \Imagine\Image\Color $filteredColor
  */
 public function testGrayscaling(BoxInterface $size, Color $color, Color $filteredColor)
 {
     $image = $this->getImage();
     $imageWidth = $size->getWidth();
     $imageHeight = $size->getHeight();
     $size = $this->getMock('Imagine\\Image\\BoxInterface');
     $size->expects($this->exactly($imageWidth + 1))->method('getWidth')->will($this->returnValue($imageWidth));
     $size->expects($this->exactly($imageWidth * ($imageHeight + 1)))->method('getHeight')->will($this->returnValue($imageHeight));
     $image->expects($this->any())->method('getSize')->will($this->returnValue($size));
     $image->expects($this->exactly($imageWidth * $imageHeight))->method('getColorAt')->will($this->returnValue($color));
     $draw = $this->getDrawer();
     $draw->expects($this->exactly($imageWidth * $imageHeight))->method('dot')->with($this->isInstanceOf('Imagine\\Image\\Point'), $this->equalTo($filteredColor));
     $image->expects($this->exactly($imageWidth * $imageHeight))->method('draw')->will($this->returnValue($draw));
     $filter = new Grayscale();
     $this->assertSame($image, $filter->apply($image));
 }
Ejemplo n.º 12
0
 /**
  * {@inheritdoc}
  */
 public function create(BoxInterface $size, ColorInterface $color = null)
 {
     if (null !== $color) {
         throw new InvalidArgumentException('Imagine SVG does not support colors');
     }
     $document = new \DOMDocument();
     $svg = $document->createElementNS('http://www.w3.org/2000/svg', 'svg');
     $svg->setAttribute('version', '1.1');
     if ($size->getWidth()) {
         $svg->setAttribute('width', $size->getWidth());
     }
     if ($size->getHeight()) {
         $svg->setAttribute('height', $size->getHeight());
     }
     $document->appendChild($svg);
     return new Image($document, new MetadataBag());
 }
Ejemplo n.º 13
0
 /**
  * (non-PHPdoc)
  * @see Imagine\Image\ImagineInterface::create()
  */
 public function create(BoxInterface $size, Color $color = null)
 {
     $width = $size->getWidth();
     $height = $size->getHeight();
     $color = null !== $color ? $color : new Color('fff');
     $gmagick = new \Gmagick();
     $pixel = new \GmagickPixel((string) $color);
     if ($color->getAlpha() > 0) {
         // TODO: implement support for transparent background
         throw new RuntimeException('alpha transparency not implemented');
     }
     $gmagick->newimage($width, $height, $pixel->getcolor(false));
     $gmagick->setimagecolorspace(\Gmagick::COLORSPACE_TRANSPARENT);
     // this is needed to propagate transparency
     $gmagick->setimagebackgroundcolor($pixel);
     return new Image($gmagick);
 }
Ejemplo n.º 14
0
 public function crop(PointInterface $start, BoxInterface $size)
 {
     if ($this->image === null) {
         $this->load();
     }
     $width = $size->getWidth();
     $height = $size->getHeight();
     $magick = $this->image->getImagick();
     try {
         $magick->cropImage($width, $height, $start->getX(), $start->getY());
         $magick->setImagePage(0, 0, 0, 0);
         // Reset canvas for gif format
     } catch (\ImagickException $e) {
         throw new \Imagine\Exception\RuntimeException('Imagick: Crop operation failed', $e->getCode(), $e);
     }
     $this->size = array($width, $height);
     return $this;
 }
Ejemplo n.º 15
0
 /**
  * Calculates coordinates of top left corner of layer that should be positioned on canvas using given
  * vertical and horizontal positions.
  *
  * @param BoxInterface      $canvas_size         Size of canvas
  * @param BoxInterface      $layer_size          Size of layer
  * @param string            $horizontal_position left|center|right
  * @param string            $vertical_position   top|center|bottom
  * @param BoxInterface|null $padding             Optional padding between canvas and layer sides.
  *
  * @return Point
  */
 public static function positionLayerOnCanvas(BoxInterface $canvas_size, BoxInterface $layer_size, $horizontal_position, $vertical_position, BoxInterface $padding = null)
 {
     $dest_x = $dest_y = 0;
     $original_width = $canvas_size->getWidth();
     $original_height = $canvas_size->getHeight();
     if ($padding instanceof BoxInterface) {
         $delta_x = $padding->getWidth();
         $delta_y = $padding->getHeight();
     } else {
         $delta_x = 0;
         $delta_y = 0;
     }
     $new_wt_width = $layer_size->getWidth();
     $new_wt_height = $layer_size->getHeight();
     if ($new_wt_width + $delta_x > $original_width) {
         $new_wt_height = $new_wt_height * ($original_width - $delta_x) / $new_wt_width;
         $new_wt_width = $original_width - $delta_x;
     }
     if ($new_wt_height > $original_height) {
         $new_wt_width = $new_wt_width * ($original_height - $delta_y) / $new_wt_height;
         $new_wt_height = $original_height - $delta_y;
     }
     if ($vertical_position == 'top') {
         $dest_y = $delta_y;
     } elseif ($vertical_position == 'center') {
         $dest_y = (int) (($original_height - $new_wt_height) / 2);
     } elseif ($vertical_position == 'bottom') {
         $dest_y = $original_height - $new_wt_height - $delta_y;
     }
     if ($horizontal_position == 'left') {
         $dest_x = $delta_x;
     } elseif ($horizontal_position == 'center') {
         $dest_x = (int) (($original_width - $new_wt_width) / 2);
     } elseif ($horizontal_position == 'right') {
         $dest_x = $original_width - $new_wt_width - $delta_x;
     }
     if ($dest_x < 1) {
         $dest_x = 0;
     }
     if ($dest_y < 1) {
         $dest_y = 0;
     }
     return new Point($dest_x, $dest_y);
 }
Ejemplo n.º 16
0
 public function create(BoxInterface $size, ColorInterface $color = null)
 {
     $width = $size->getWidth();
     $height = $size->getHeight();
     $color = self::getColor($color);
     try {
         $pixel = new \ImagickPixel($color['color']);
         $pixel->setColorValue(\Imagick::COLOR_OPACITY, $color['alpha']);
         $magick = new \Imagick();
         $magick->newImage($width, $height, $pixel);
         $magick->setImageMatte(true);
         $magick->setImageBackgroundColor($pixel);
         $pixel->clear();
         $pixel->destroy();
         return new RImage($magick, $color['palette'], self::$emptyBag, array($width, $height));
     } catch (\Exception $e) {
         throw new \Imagine\Exception\RuntimeException("Imagick: Could not create empty image {$e->getMessage()}", $e->getCode(), $e);
     }
 }
Ejemplo n.º 17
0
 /**
  * @param array | BoxInterface $data
  *
  * @throws \Zf2FileUploader\Filter\Thumbnail\Exception\InvalidArgumentException
  * @return PathFilter
  */
 public function getPathFilter($data)
 {
     if ($data instanceof BoxInterface) {
         $width = $data->getWidth();
         $height = $data->getHeight();
     } else {
         if (func_num_args() > 1) {
             list($width, $height) = func_get_args();
         } else {
             if (is_array($data) && array_key_exists('width', $data) && array_key_exists('height', $data) || preg_match('/^(?P<width>[0-9]+)x(?P<height>[0-9]+)$/', $data, $data)) {
                 $width = $data['width'];
                 $height = $data['height'];
             } else {
                 throw new Exception\InvalidArgumentException("Could not retrieve width and height from data");
             }
         }
     }
     return new PathFilter($width, $height);
 }
Ejemplo n.º 18
0
 /**
  * {@inheritdoc}
  */
 public function isEqualTo($coordinates)
 {
     if ($coordinates instanceof BoxInterface) {
         $coordinates = new static($coordinates, new Point(0, 0), $coordinates);
     }
     if (!$coordinates instanceof ResizeCoordinatesInterface) {
         throw new \InvalidArgumentException(sprintf('$coordinates must be an instance of ResizeCoordinatesInterface or BoxInterface, "%s" given', get_class($coordinates)));
     }
     /* @var ResizeCoordinatesInterface $coordinates */
     return $this->cropStart->getX() === $coordinates->getCropStart()->getX() && $this->cropStart->getY() === $coordinates->getCropStart()->getY() && $this->cropSize->getWidth() === $coordinates->getCropSize()->getWidth() && $this->cropSize->getHeight() === $coordinates->getCropSize()->getHeight() && $this->size->getWidth() === $coordinates->getSize()->getWidth() && $this->size->getHeight() === $coordinates->getSize()->getHeight();
 }
Ejemplo n.º 19
0
 /**
  * resizes image using a focal point
  * @param  ImageInterface $image  an Imagine image
  * @param  BoxInterface   $size   size of resized imaga
  * @param  FocalPoint     $focal  focal point to use for size
  * @param  string         $filter Imagine filter to use
  * @return ImageInterface resized image
  */
 public function resize(ImageInterface $image, BoxInterface $size, FocalPointInterface $focal, $filter = ImageInterface::FILTER_UNDEFINED)
 {
     $origSize = $image->getSize();
     $origWidth = $origSize->getWidth();
     $origHeight = $origSize->getHeight();
     $width = $size->getWidth();
     $height = $size->getHeight();
     $ratioHeight = $origHeight / $height;
     $ratioWidth = $origWidth / $width;
     if ($ratioHeight < $ratioWidth) {
         list($cropX1, $cropX2) = $this->calculateCrop($origWidth, $width, $focal->getX(), $ratioHeight);
         $cropY1 = 0;
         $cropY2 = $origHeight;
     } else {
         list($cropY1, $cropY2) = $this->calculateCrop($origHeight, $height, -$focal->getY(), $ratioWidth);
         $cropX1 = 0;
         $cropX2 = $origWidth;
     }
     $image->crop(new Point($cropX1, $cropY1), new Box($cropX2 - $cropX1, $cropY2 - $cropY1))->resize(new Box($width, $height, $filter));
     return $image;
 }
Ejemplo n.º 20
0
 /**
  * {@inheritdoc}
  */
 public function thumbnail(BoxInterface $size, $mode = ImageInterface::THUMBNAIL_INSET, $filter = ImageInterface::FILTER_UNDEFINED)
 {
     if ($mode !== ImageInterface::THUMBNAIL_INSET && $mode !== ImageInterface::THUMBNAIL_OUTBOUND) {
         throw new InvalidArgumentException('Invalid mode specified');
     }
     $imageSize = $this->getSize();
     $ratios = array($size->getWidth() / $imageSize->getWidth(), $size->getHeight() / $imageSize->getHeight());
     $thumbnail = $this->copy();
     $thumbnail->usePalette($this->palette());
     $thumbnail->strip();
     // if target width is larger than image width
     // AND target height is longer than image height
     if ($size->contains($imageSize)) {
         return $thumbnail;
     }
     if ($mode === ImageInterface::THUMBNAIL_INSET) {
         $ratio = min($ratios);
     } else {
         $ratio = max($ratios);
     }
     if ($mode === ImageInterface::THUMBNAIL_OUTBOUND) {
         if (!$imageSize->contains($size)) {
             $size = new Box(min($imageSize->getWidth(), $size->getWidth()), min($imageSize->getHeight(), $size->getHeight()));
         } else {
             $imageSize = $thumbnail->getSize()->scale($ratio);
             $thumbnail->resize($imageSize, $filter);
         }
         $thumbnail->crop(new Point(max(0, round(($imageSize->getWidth() - $size->getWidth()) / 2)), max(0, round(($imageSize->getHeight() - $size->getHeight()) / 2))), $size);
     } else {
         if (!$imageSize->contains($size)) {
             $imageSize = $imageSize->scale($ratio);
             $thumbnail->resize($imageSize, $filter);
         } else {
             $imageSize = $thumbnail->getSize()->scale($ratio);
             $thumbnail->resize($imageSize, $filter);
         }
     }
     return $thumbnail;
 }
Ejemplo n.º 21
0
 /**
  * {@inheritdoc}
  */
 public function create(BoxInterface $size, ColorInterface $color = null)
 {
     $width = $size->getWidth();
     $height = $size->getHeight();
     $palette = null !== $color ? $color->getPalette() : new RGB();
     $color = null !== $color ? $color : $palette->color('fff');
     try {
         $pixel = new \ImagickPixel((string) $color);
         $pixel->setColorValue(Imagick::COLOR_ALPHA, $color->getAlpha() / 100);
         $imagick = new Imagick();
         $imagick->newImage($width, $height, $pixel);
         $imagick->setImageMatte(true);
         $imagick->setImageBackgroundColor($pixel);
         if (version_compare('6.3.1', $this->getVersion($imagick)) < 0) {
             $imagick->setImageOpacity($pixel->getColorValue(Imagick::COLOR_ALPHA));
         }
         $pixel->clear();
         $pixel->destroy();
         return new Image($imagick, $palette, new MetadataBag());
     } catch (\ImagickException $e) {
         throw new RuntimeException('Could not create empty image', $e->getCode(), $e);
     }
 }
Ejemplo n.º 22
0
 /**
  * {@inheritdoc}
  */
 public function in(BoxInterface $box)
 {
     return $this->x < $box->getWidth() && $this->y < $box->getHeight();
 }
Ejemplo n.º 23
0
 /**
  * {@inheritdoc}
  *
  * @return ImageInterface
  */
 public function resize(BoxInterface $size, $filter = ImageInterface::FILTER_UNDEFINED)
 {
     try {
         $this->imagick->resizeImage($size->getWidth(), $size->getHeight(), $this->getFilter($filter), 1);
     } catch (\ImagickException $e) {
         throw new RuntimeException('Resize operation failed', $e->getCode(), $e);
     }
     return $this;
 }
Ejemplo n.º 24
0
 /**
  * Internal
  *
  * Generates a GD image
  *
  * @param BoxInterface $size
  * @param  string the operation initiating the creation
  *
  * @return resource
  *
  * @throws RuntimeException
  *
  */
 private function createImage(BoxInterface $size, $operation)
 {
     $resource = imagecreatetruecolor($size->getWidth(), $size->getHeight());
     if (false === $resource) {
         throw new RuntimeException('Image ' . $operation . ' failed');
     }
     if (false === imagealphablending($resource, false) || false === imagesavealpha($resource, true)) {
         throw new RuntimeException('Image ' . $operation . ' failed');
     }
     if (function_exists('imageantialias')) {
         imageantialias($resource, true);
     }
     $transparent = imagecolorallocatealpha($resource, 255, 255, 255, 127);
     imagefill($resource, 0, 0, $transparent);
     imagecolortransparent($resource, $transparent);
     return $resource;
 }
Ejemplo n.º 25
0
 /**
  * {@inheritdoc}
  */
 public function pieSlice(PointInterface $center, BoxInterface $size, $start, $end, ColorInterface $color, $fill = false, $thickness = 1)
 {
     $width = $size->getWidth();
     $height = $size->getHeight();
     $x1 = round($center->getX() + $width / 2 * cos(deg2rad($start)));
     $y1 = round($center->getY() + $height / 2 * sin(deg2rad($start)));
     $x2 = round($center->getX() + $width / 2 * cos(deg2rad($end)));
     $y2 = round($center->getY() + $height / 2 * sin(deg2rad($end)));
     if ($fill) {
         $this->chord($center, $size, $start, $end, $color, true, $thickness);
         $this->polygon(array($center, new Point($x1, $y1), new Point($x2, $y2)), $color, true, $thickness);
     } else {
         $this->arc($center, $size, $start, $end, $color, $thickness);
         $this->line($center, new Point($x1, $y1), $color, $thickness);
         $this->line($center, new Point($x2, $y2), $color, $thickness);
     }
     return $this;
 }
 /**
  * {@inheritdoc}
  */
 public function getStartPoint(BoxInterface $box)
 {
     return new Point($this->getX() - $box->getWidth() / 2, $this->getY() - $box->getHeight() / 2);
 }
Ejemplo n.º 27
0
 /**
  * @param BoxInterface $originalSize
  * @return string
  */
 protected function getTestImage(BoxInterface $originalSize)
 {
     ob_start();
     imagejpeg(imagecreatetruecolor($originalSize->getWidth(), $originalSize->getHeight()));
     return ob_get_clean();
 }
Ejemplo n.º 28
0
 /**
  * 
  * @param \Imagine\Image\BoxInterface $image
  * @param \Imagine\Image\BoxInterface $boxToCenter
  * @param integer $offsetY
  * @return \Imagine\Image\PointInterface
  */
 public function getStartingPointForCenteredBox(BoxInterface $image, BoxInterface $boxToCenter, $offsetY = 0)
 {
     $x = ($image->getWidth() - $boxToCenter->getWidth()) / 2;
     return new Point($x, $offsetY);
 }
Ejemplo n.º 29
0
 /**
  * {@inheritdoc}
  */
 public function resize(BoxInterface $size, $filter = ImageInterface::FILTER_UNDEFINED)
 {
     static $supportedFilters = array(ImageInterface::FILTER_UNDEFINED => \Gmagick::FILTER_UNDEFINED, ImageInterface::FILTER_BESSEL => \Gmagick::FILTER_BESSEL, ImageInterface::FILTER_BLACKMAN => \Gmagick::FILTER_BLACKMAN, ImageInterface::FILTER_BOX => \Gmagick::FILTER_BOX, ImageInterface::FILTER_CATROM => \Gmagick::FILTER_CATROM, ImageInterface::FILTER_CUBIC => \Gmagick::FILTER_CUBIC, ImageInterface::FILTER_GAUSSIAN => \Gmagick::FILTER_GAUSSIAN, ImageInterface::FILTER_HANNING => \Gmagick::FILTER_HANNING, ImageInterface::FILTER_HAMMING => \Gmagick::FILTER_HAMMING, ImageInterface::FILTER_HERMITE => \Gmagick::FILTER_HERMITE, ImageInterface::FILTER_LANCZOS => \Gmagick::FILTER_LANCZOS, ImageInterface::FILTER_MITCHELL => \Gmagick::FILTER_MITCHELL, ImageInterface::FILTER_POINT => \Gmagick::FILTER_POINT, ImageInterface::FILTER_QUADRATIC => \Gmagick::FILTER_QUADRATIC, ImageInterface::FILTER_SINC => \Gmagick::FILTER_SINC, ImageInterface::FILTER_TRIANGLE => \Gmagick::FILTER_TRIANGLE);
     if (!array_key_exists($filter, $supportedFilters)) {
         throw new InvalidArgumentException('Unsupported filter type');
     }
     try {
         $this->gmagick->resizeimage($size->getWidth(), $size->getHeight(), $supportedFilters[$filter], 1);
     } catch (\GmagickException $e) {
         throw new RuntimeException('Resize operation failed', $e->getCode(), $e);
     }
     return $this;
 }
Ejemplo n.º 30
0
 /**
  * {@inheritdoc}
  */
 public function thumbnail(BoxInterface $size, $mode = ImageInterface::THUMBNAIL_INSET)
 {
     if ($mode !== ImageInterface::THUMBNAIL_INSET && $mode !== ImageInterface::THUMBNAIL_OUTBOUND) {
         throw new InvalidArgumentException('Invalid mode specified');
     }
     $width = $size->getWidth();
     $height = $size->getHeight();
     $thumbnail = $this->copy();
     try {
         if ($mode === ImageInterface::THUMBNAIL_INSET) {
             $thumbnail->imagick->thumbnailImage($width, $height, true);
         } elseif ($mode === ImageInterface::THUMBNAIL_OUTBOUND) {
             $thumbnail->imagick->cropThumbnailImage($width, $height);
         }
     } catch (\ImagickException $e) {
         throw new RuntimeException('Thumbnail operation failed', $e->getCode(), $e);
     }
     return $thumbnail;
 }