Rectangle.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace Grafika\Imagick\DrawingObject;
  3. use Grafika\DrawingObject\Rectangle as Base;
  4. use Grafika\DrawingObjectInterface;
  5. /**
  6. * Class Rectangle
  7. * @package Grafika
  8. */
  9. class Rectangle extends Base implements DrawingObjectInterface{
  10. public function draw( $image ) {
  11. $draw = new \ImagickDraw();
  12. $draw->setStrokeWidth($this->borderSize);
  13. if(null !== $this->fillColor) {
  14. $fillColor = new \ImagickPixel( $this->fillColor->getHexString() );
  15. $draw->setFillColor($fillColor);
  16. } else {
  17. $draw->setFillOpacity(0);
  18. }
  19. if(null !== $this->borderColor) {
  20. $borderColor = new \ImagickPixel( $this->borderColor->getHexString() );
  21. $draw->setStrokeColor($borderColor);
  22. } else {
  23. $draw->setStrokeOpacity(0);
  24. }
  25. $x1 = $this->pos[0];
  26. $x2 = $x1 + $this->getWidth();
  27. $y1 = $this->pos[1];
  28. $y2 = $y1 + $this->getHeight();
  29. $draw->rectangle( $x1, $y1, $x2, $y2 );
  30. $image->getCore()->drawImage($draw);
  31. return $image;
  32. }
  33. }