AbstractShape.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace Intervention\Image;
  3. abstract class AbstractShape
  4. {
  5. /**
  6. * Background color of shape
  7. *
  8. * @var string
  9. */
  10. public $background;
  11. /**
  12. * Border color of current shape
  13. *
  14. * @var string
  15. */
  16. public $border_color;
  17. /**
  18. * Border width of shape
  19. *
  20. * @var int
  21. */
  22. public $border_width = 0;
  23. /**
  24. * Draws shape to given image on given position
  25. *
  26. * @param Image $image
  27. * @param int $posx
  28. * @param int $posy
  29. * @return boolean
  30. */
  31. abstract public function applyToImage(Image $image, $posx = 0, $posy = 0);
  32. /**
  33. * Set text to be written
  34. *
  35. * @param string $text
  36. * @return void
  37. */
  38. public function background($color)
  39. {
  40. $this->background = $color;
  41. }
  42. /**
  43. * Set border width and color of current shape
  44. *
  45. * @param int $width
  46. * @param string $color
  47. * @return void
  48. */
  49. public function border($width, $color = null)
  50. {
  51. $this->border_width = is_numeric($width) ? intval($width) : 0;
  52. $this->border_color = is_null($color) ? '#000000' : $color;
  53. }
  54. /**
  55. * Determines if current shape has border
  56. *
  57. * @return boolean
  58. */
  59. public function hasBorder()
  60. {
  61. return ($this->border_width >= 1);
  62. }
  63. }