10
10
* @access public
11
11
* @see https://github.com/DantSu/php-image-editor Github page of this project
12
12
*/
13
-
14
13
class Image
15
14
{
16
15
const ALIGN_LEFT = 'left ' ;
@@ -664,10 +663,10 @@ public function pasteOn(Image $image, $posX = Image::ALIGN_CENTER, $posY = Image
664
663
if (!$ this ->isImageDefined () || !$ image ->isImageDefined ()) {
665
664
return $ this ;
666
665
}
667
-
666
+
668
667
return $ this ->pasteGdImageOn ($ image ->getImage (), $ image ->getWidth (), $ image ->getHeight (), $ posX , $ posY );
669
668
}
670
-
669
+
671
670
/**
672
671
* Paste the image at $posX and $posY position (You can use `Image::ALIGN_...`).
673
672
*
@@ -683,7 +682,7 @@ public function pasteGdImageOn($image, int $imageWidth, int $imageHeight, $posX
683
682
if (!$ this ->isImageDefined () || !static ::isGdImage ($ image )) {
684
683
return $ this ;
685
684
}
686
-
685
+
687
686
$ posX = $ this ->convertPosX ($ posX , $ imageWidth );
688
687
$ posY = $ this ->convertPosY ($ posY , $ imageHeight );
689
688
@@ -939,6 +938,33 @@ public function drawRectangle(int $left, int $top, int $right, int $bottom, stri
939
938
return $ this ;
940
939
}
941
940
941
+ /**
942
+ * Draw a polygon.
943
+ *
944
+ * @param int[] $points Array of polygon's points [x1, y1, x2, y2, x3, y3...]
945
+ * @param string $color Hexadecimal string color
946
+ * @return $this Fluent interface
947
+ */
948
+ public function drawPolygon (array $ points , string $ color = '#000000 ' , $ antialias = false ): Image
949
+ {
950
+ if (!$ this ->isImageDefined ()) {
951
+ return $ this ;
952
+ }
953
+
954
+ $ color = $ this ->colorAllocate ($ color );
955
+
956
+ if ($ color === false ) {
957
+ return $ this ;
958
+ }
959
+
960
+ if ($ antialias ) {
961
+ \imageantialias ($ this ->image , true );
962
+ \imagepolygon ($ this ->image , $ points , \count ($ points ) / 2 , $ color );
963
+ }
964
+ \imagefilledpolygon ($ this ->image , $ points , \count ($ points ) / 2 , $ color );
965
+
966
+ return $ this ;
967
+ }
942
968
943
969
/**
944
970
* Draw a Line from `$originX, $originY` to `$dstX, $dstY`.
@@ -974,39 +1000,27 @@ public function drawLine(int $originX, int $originY, int $dstX, int $dstY, int $
974
1000
*/
975
1001
public function drawLineWithAngle (int $ originX , int $ originY , float $ angle , float $ length , int $ weight , string $ color = '#000000 ' ): Image
976
1002
{
977
- if (!$ this ->isImageDefined ()) {
978
- return $ this ;
979
- }
980
-
981
- $ color = $ this ->colorAllocate ($ color );
982
-
983
- if ($ color === false ) {
984
- return $ this ;
985
- }
986
-
987
1003
$ angle = Geometry2D::degrees0to360 ($ angle );
988
1004
989
1005
$ points1 = Geometry2D::getDstXY ($ originX , $ originY , Geometry2D::degrees0to360 ($ angle - 90 ), \floor ($ weight / 2 ));
990
1006
$ points2 = Geometry2D::getDstXY ($ points1 ['x ' ], $ points1 ['y ' ], $ angle , $ length );
991
1007
$ points4 = Geometry2D::getDstXY ($ originX , $ originY , Geometry2D::degrees0to360 ($ angle + 90 ), \floor ($ weight / 2 ));
992
1008
$ points3 = Geometry2D::getDstXY ($ points4 ['x ' ], $ points4 ['y ' ], $ angle , $ length );
993
1009
994
- $ points = [
995
- \round ($ points1 ['x ' ]),
996
- \round ($ points1 ['y ' ]),
997
- \round ($ points2 ['x ' ]),
998
- \round ($ points2 ['y ' ]),
999
- \round ($ points3 ['x ' ]),
1000
- \round ($ points3 ['y ' ]),
1001
- \round ($ points4 ['x ' ]),
1002
- \round ($ points4 ['y ' ])
1003
- ];
1004
-
1005
- \imageantialias ($ this ->image , true );
1006
- \imagepolygon ($ this ->image , $ points , 4 , $ color );
1007
- \imagefilledpolygon ($ this ->image , $ points , 4 , $ color );
1008
-
1009
- return $ this ;
1010
+ return $ this ->drawPolygon (
1011
+ [
1012
+ \round ($ points1 ['x ' ]),
1013
+ \round ($ points1 ['y ' ]),
1014
+ \round ($ points2 ['x ' ]),
1015
+ \round ($ points2 ['y ' ]),
1016
+ \round ($ points3 ['x ' ]),
1017
+ \round ($ points3 ['y ' ]),
1018
+ \round ($ points4 ['x ' ]),
1019
+ \round ($ points4 ['y ' ])
1020
+ ],
1021
+ $ color ,
1022
+ true
1023
+ );
1010
1024
}
1011
1025
1012
1026
/**
@@ -1020,7 +1034,7 @@ public function drawLineWithAngle(int $originX, int $originY, float $angle, floa
1020
1034
* @param string $color Hexadecimal string color
1021
1035
* @return $this Fluent interface
1022
1036
*/
1023
- public function drawArrowWithAngle (int $ originX , int $ originY , float $ angle , float $ length , int $ weight , string $ color = '#000000 ' ): Image
1037
+ public function drawArrowWithAngle (int $ originX , int $ originY , float $ angle , float $ length , int $ weight , string $ color = '#000000 ' ): Image
1024
1038
{
1025
1039
if (!$ this ->isImageDefined ()) {
1026
1040
return $ this ;
0 commit comments