File indexing completed on 2025-01-26 05:29:14

0001 <?php
0002 
0003 namespace Intervention\Image\Imagick\Shapes;
0004 
0005 use Intervention\Image\Image;
0006 use Intervention\Image\Imagick\Color;
0007 
0008 class EllipseShape extends \Intervention\Image\AbstractShape
0009 {
0010     /**
0011      * Width of ellipse in pixels
0012      *
0013      * @var int
0014      */
0015     public $width = 100;
0016 
0017     /**
0018      * Height of ellipse in pixels
0019      *
0020      * @var int
0021      */
0022     public $height = 100;
0023 
0024     /**
0025      * Create new ellipse instance
0026      *
0027      * @param int $width
0028      * @param int $height
0029      */
0030     public function __construct($width = null, $height = null)
0031     {
0032         $this->width = is_numeric($width) ? intval($width) : $this->width;
0033         $this->height = is_numeric($height) ? intval($height) : $this->height;
0034     }
0035 
0036     /**
0037      * Draw ellipse instance on given image
0038      *
0039      * @param  Image   $image
0040      * @param  int     $x
0041      * @param  int     $y
0042      * @return boolean
0043      */
0044     public function applyToImage(Image $image, $x = 0, $y = 0)
0045     {
0046         $circle = new \ImagickDraw;
0047 
0048         // set background
0049         $bgcolor = new Color($this->background);
0050         $circle->setFillColor($bgcolor->getPixel());
0051 
0052         // set border
0053         if ($this->hasBorder()) {
0054             $border_color = new Color($this->border_color);
0055             $circle->setStrokeWidth($this->border_width);
0056             $circle->setStrokeColor($border_color->getPixel());
0057         }
0058 
0059         $circle->ellipse($x, $y, $this->width / 2, $this->height / 2, 0, 360);
0060 
0061         $image->getCore()->drawImage($circle);
0062 
0063         return true;
0064     }
0065 }