Просмотр файла vendor/intervention/image/src/Intervention/Image/Gd/Shapes/EllipseShape.php

Размер файла: 1.76Kb
  1. <?php
  2.  
  3. namespace Intervention\Image\Gd\Shapes;
  4.  
  5. use Intervention\Image\AbstractShape;
  6. use Intervention\Image\Gd\Color;
  7. use Intervention\Image\Image;
  8.  
  9. class EllipseShape extends AbstractShape
  10. {
  11. /**
  12. * Width of ellipse in pixels
  13. *
  14. * @var int
  15. */
  16. public $width = 100;
  17.  
  18. /**
  19. * Height of ellipse in pixels
  20. *
  21. * @var int
  22. */
  23. public $height = 100;
  24.  
  25. /**
  26. * Create new ellipse instance
  27. *
  28. * @param int $width
  29. * @param int $height
  30. */
  31. public function __construct($width = null, $height = null)
  32. {
  33. $this->width = is_numeric($width) ? intval($width) : $this->width;
  34. $this->height = is_numeric($height) ? intval($height) : $this->height;
  35. }
  36.  
  37. /**
  38. * Draw ellipse instance on given image
  39. *
  40. * @param Image $image
  41. * @param int $x
  42. * @param int $y
  43. * @return boolean
  44. */
  45. public function applyToImage(Image $image, $x = 0, $y = 0)
  46. {
  47. // parse background color
  48. $background = new Color($this->background);
  49.  
  50. if ($this->hasBorder()) {
  51. // slightly smaller ellipse to keep 1px bordered edges clean
  52. imagefilledellipse($image->getCore(), $x, $y, $this->width-1, $this->height-1, $background->getInt());
  53.  
  54. $border_color = new Color($this->border_color);
  55. imagesetthickness($image->getCore(), $this->border_width);
  56.  
  57. // gd's imageellipse doesn't respect imagesetthickness so i use imagearc with 359.9 degrees here
  58. imagearc($image->getCore(), $x, $y, $this->width, $this->height, 0, 359.99, $border_color->getInt());
  59. } else {
  60. imagefilledellipse($image->getCore(), $x, $y, $this->width, $this->height, $background->getInt());
  61. }
  62.  
  63. return true;
  64. }
  65. }