QuadraticBezier.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace Grafika\Imagick\DrawingObject;
  3. use Grafika\DrawingObject\QuadraticBezier as Base;
  4. use Grafika\DrawingObjectInterface;
  5. use Grafika\Imagick\Image;
  6. use Grafika\ImageInterface;
  7. /**
  8. * Class QuadraticBezier
  9. * @package Grafika
  10. */
  11. class QuadraticBezier extends Base implements DrawingObjectInterface
  12. {
  13. /**
  14. * @param ImageInterface $image
  15. * @return Image
  16. */
  17. public function draw($image)
  18. {
  19. // Localize vars
  20. $width = $image->getWidth();
  21. $height = $image->getHeight();
  22. $imagick = $image->getCore();
  23. $draw = new \ImagickDraw();
  24. $strokeColor = new \ImagickPixel($this->getColor()->getHexString());
  25. $fillColor = new \ImagickPixel('rgba(0,0,0,0)');
  26. $draw->setStrokeOpacity(1);
  27. $draw->setStrokeColor($strokeColor);
  28. $draw->setFillColor($fillColor);
  29. list($x1, $y1) = $this->point1;
  30. list($x2, $y2) = $this->control;
  31. list($x3, $y3) = $this->point2;
  32. $draw->pathStart();
  33. $draw->pathMoveToAbsolute($x1, $y1);
  34. $draw->pathCurveToQuadraticBezierAbsolute(
  35. $x2, $y2,
  36. $x3, $y3
  37. );
  38. $draw->pathFinish();
  39. // Render the draw commands in the ImagickDraw object
  40. $imagick->drawImage($draw);
  41. $type = $image->getType();
  42. $file = $image->getImageFile();
  43. return new Image($imagick, $file, $width, $height, $type); // Create new image with updated core
  44. }
  45. }