Ellipse.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace Grafika\Gd\DrawingObject;
  3. use Grafika\DrawingObject\Ellipse as Base;
  4. use Grafika\DrawingObjectInterface;
  5. use Grafika\Gd\Editor;
  6. use Grafika\ImageInterface;
  7. /**
  8. * Class Ellipse
  9. * @package Grafika
  10. */
  11. class Ellipse extends Base implements DrawingObjectInterface
  12. {
  13. /**
  14. * TODO: Anti-aliased curves
  15. * @param ImageInterface $image
  16. * @return ImageInterface
  17. */
  18. public function draw($image)
  19. {
  20. list($x, $y) = $this->pos;
  21. $left = $x + $this->width / 2;
  22. $top = $y + $this->height / 2;
  23. if( null !== $this->fillColor ){
  24. list($r, $g, $b, $alpha) = $this->fillColor->getRgba();
  25. $fillColorResource = imagecolorallocatealpha($image->getCore(), $r, $g, $b, Editor::gdAlpha($alpha));
  26. imagefilledellipse($image->getCore(), $left, $top, $this->width, $this->height, $fillColorResource);
  27. }
  28. // Create borders. It will be placed on top of the filled ellipse (if present)
  29. if ( 0 < $this->getBorderSize() and null !== $this->borderColor) { // With border > 0 AND borderColor !== null
  30. list($r, $g, $b, $alpha) = $this->borderColor->getRgba();
  31. $borderColorResource = imagecolorallocatealpha($image->getCore(), $r, $g, $b, Editor::gdAlpha($alpha));
  32. imageellipse($image->getCore(), $left, $top, $this->width, $this->height, $borderColorResource);
  33. }
  34. return $image;
  35. }
  36. }