Line.php 863 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace Grafika\Gd\DrawingObject;
  3. use Grafika\DrawingObject\Line as Base;
  4. use Grafika\DrawingObjectInterface;
  5. use Grafika\Gd\Image;
  6. /**
  7. * Class Line
  8. * @package Grafika
  9. */
  10. class Line extends Base implements DrawingObjectInterface
  11. {
  12. /**
  13. * @param Image $image
  14. *
  15. * @return Image
  16. */
  17. public function draw($image)
  18. {
  19. list( $x1, $y1 ) = $this->point1;
  20. list( $x2, $y2 ) = $this->point2;
  21. list( $r, $g, $b ) = $this->color->getRgb();
  22. $color = imagecolorallocate( $image->getCore(), $r, $g, $b );
  23. if ( function_exists( 'imageantialias' ) ) { // Not available on some if PHP is not precompiled with it even if GD is enabled
  24. imageantialias( $image->getCore(), true );
  25. }
  26. imageline( $image->getCore(), $x1, $y1, $x2, $y2, $color );
  27. return $image;
  28. }
  29. }