public function drawPolygon(Image_3D_Polygon $polygon) { // Get points $points = $polygon->getPoints(); $coords = array(); foreach ($points as $point) { $coords = array_merge($coords, $point->getScreenCoordinates()); } $coordCount = (int) (count($coords) / 2); if (true) { imageFilledPolygon($this->_image, $coords, $coordCount, $this->_getColor($polygon->getColor())); } else { imagePolygon($this->_image, $coords, $coordCount, $this->_getColor($polygon->getColor())); } }
function draw_polygon($points, $num_points, $color, $filled) { if ($filled) { imageFilledPolygon($this->image, $points, $num_points, $color); } else { imagePolygon($this->image, $points, $num_points, $color); } }
/** * Function: drawPolygon * * Draws the given polygon. */ function drawPolygon($points, $fill = null, $stroke = null, $shadow = false) { if (isset($this->image)) { $n = sizeof($points) / 2; if (isset($fill)) { if ($shadow) { imageFilledPolygon($this->image, $this->offset($points), $n, $this->shadowColor); } $fill = $this->getColor($fill); imageFilledPolygon($this->image, $points, $n, $fill); } if (isset($stroke)) { $stroke = $this->getColor($stroke); imagePolygon($this->image, $points, $n, $stroke); } } }
$i = imageCreateTrueColor(500, 300); /* Подготовка к работе */ imageAntiAlias($i, true); $red = imageColorAllocate($i, 255, 0, 0); $white = imageColorAllocate($i, 0xff, 0xff, 0xff); $black = imageColorAllocate($i, 0, 0, 0); $green = imageColorAllocate($i, 0, 255, 0); $blue = imageColorAllocate($i, 0, 0, 255); $grey = imageColorAllocate($i, 192, 192, 192); imageFill($i, 0, 0, $grey); /* Рисуем примитивы */ imageSetPixel($i, 10, 10, $black); imageLine($i, 20, 20, 280, 180, $red); imageRectangle($i, 20, 20, 280, 180, $blue); //array of dots $points = [120, 120, 100, 200, 300, 200]; imagePolygon($i, $points, 3, $green); imageEllipse($i, 200, 150, 300, 200, $red); // imageArc($i, 210, 160, 300, 200, 0, 90, $black); imageFilledArc($i, 200, 150, 300, 200, 0, 40, $red, IMG_ARC_PIE); /* Рисуем текст */ imageString($i, 5, 150, 200, 'php7', $black); imageCharUp($i, 3, 200, 200, 'PHP5', $blue); imageTtfText($i, 30, 10, 300, 150, $green, 'arial.ttf', 'PHP7'); /* Отдаем изображение */ // header("Content-type: image/gif"); // imageGif($i); header("Content-type: image/png"); imagePng($i); //header("Content-type: image/jpg"); //imageJpeg($i);
/** * Draws a polygon on the image * @param array $points Array with the vectrices of the polygon * @param Color $color The color to draw the polygon in * @return null */ public function drawPolygon(array $points, Color $color) { $color = $this->allocateColor($color); $numPoints = 0; $p = array(); foreach ($points as $point) { if (!$point) { throw new ImageException('Provided points array contains a non-Point variable'); } $p[] = $point->getX(); $p[] = $point->getY(); $numPoints++; } imagePolygon($this->resource, $p, $numPoints, $color); }