File indexing completed on 2025-01-26 05:29:14
0001 <?php 0002 0003 namespace Intervention\Image\Gd\Shapes; 0004 0005 use Intervention\Image\Image; 0006 use Intervention\Image\Gd\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 // parse background color 0047 $background = new Color($this->background); 0048 0049 if ($this->hasBorder()) { 0050 // slightly smaller ellipse to keep 1px bordered edges clean 0051 imagefilledellipse($image->getCore(), $x, $y, $this->width-1, $this->height-1, $background->getInt()); 0052 0053 $border_color = new Color($this->border_color); 0054 imagesetthickness($image->getCore(), $this->border_width); 0055 0056 // gd's imageellipse doesn't respect imagesetthickness so i use imagearc with 359.9 degrees here 0057 imagearc($image->getCore(), $x, $y, $this->width, $this->height, 0, 359.99, $border_color->getInt()); 0058 } else { 0059 imagefilledellipse($image->getCore(), $x, $y, $this->width, $this->height, $background->getInt()); 0060 } 0061 0062 return true; 0063 } 0064 }