コード例 #1
0
ファイル: PieChartGD.php プロジェクト: samchristy/piechart
 /**
  * Draws the pie chart, with optional supersampled anti-aliasing.
  * @param int $aa
  */
 public function draw($aa = 4)
 {
     $this->canvas = imageCreateTrueColor($this->width, $this->height);
     // Set anti-aliasing for the pie chart.
     imageAntiAlias($this->canvas, true);
     imageFilledRectangle($this->canvas, 0, 0, $this->width, $this->height, $this->_convertColor($this->backgroundColor));
     $total = 0;
     $sliceStart = -90;
     // Start at 12 o'clock.
     $titleHeight = $this->_drawTitle();
     $legendWidth = $this->_drawLegend($titleHeight);
     // Account for the space occupied by the legend and its padding.
     $pieCentreX = ($this->width - $legendWidth) / 2;
     // Account for the space occupied by the title.
     $pieCentreY = $titleHeight + ($this->height - $titleHeight) / 2;
     // 10% padding on the top and bottom of the pie.
     $pieDiameter = round(min($this->width - $legendWidth, $this->height - $titleHeight) * 0.85);
     foreach ($this->slices as $slice) {
         $total += $slice['value'];
     }
     // If anti-aliasing is enabled, we supersample the pie to work around
     // the fact that GD does not provide anti-aliasing natively.
     if ($aa > 0) {
         $ssDiameter = $pieDiameter * $aa;
         $ssCentreX = $ssCentreY = $ssDiameter / 2;
         $superSample = imageCreateTrueColor($ssDiameter, $ssDiameter);
         imageFilledRectangle($superSample, 0, 0, $ssDiameter, $ssDiameter, $this->_convertColor($this->backgroundColor));
         foreach ($this->slices as $slice) {
             $sliceWidth = 360 * $slice['value'] / $total;
             // Skip slices that are too small to draw / be visible.
             if ($sliceWidth == 0) {
                 continue;
             }
             $sliceEnd = $sliceStart + $sliceWidth;
             imageFilledArc($superSample, $ssCentreX, $ssCentreY, $ssDiameter, $ssDiameter, $sliceStart, $sliceEnd, $this->_convertColor($slice['color']), IMG_ARC_PIE);
             // Move along to the next slice.
             $sliceStart = $sliceEnd;
         }
         imageCopyResampled($this->canvas, $superSample, $pieCentreX - $pieDiameter / 2, $pieCentreY - $pieDiameter / 2, 0, 0, $pieDiameter, $pieDiameter, $ssDiameter, $ssDiameter);
         imageDestroy($superSample);
     } else {
         // Draw the slices.
         foreach ($this->slices as $slice) {
             $sliceWidth = 360 * $slice['value'] / $total;
             // Skip slices that are too small to draw / be visible.
             if ($sliceWidth == 0) {
                 continue;
             }
             $sliceEnd = $sliceStart + $sliceWidth;
             imageFilledArc($this->canvas, $pieCentreX, $pieCentreY, $pieDiameter, $pieDiameter, $sliceStart, $sliceEnd, $this->_convertColor($slice['color']), IMG_ARC_PIE);
             // Move along to the next slice.
             $sliceStart = $sliceEnd;
         }
     }
 }
コード例 #2
0
ファイル: skyview.php プロジェクト: leearmstrong/gpsd
function skyview($im, $sz, $C)
{
    $a = 90;
    $a = $sz * 0.95 * ($a / 180);
    imageFilledArc($im, $sz / 2, $sz / 2, $a * 2, $a * 2, 0, 360, $C['mdgray'], 0);
    imageArc($im, $sz / 2, $sz / 2, $a * 2, $a * 2, 0, 360, $C['black']);
    $x = $sz / 2 - 16;
    $y = $sz / 2 - $a;
    imageString($im, 2, $x, $y, "0", $C['ltgray']);
    $a = 85;
    $a = $sz * 0.95 * ($a / 180);
    imageFilledArc($im, $sz / 2, $sz / 2, $a * 2, $a * 2, 0, 360, $C['white'], 0);
    imageArc($im, $sz / 2, $sz / 2, $a * 2, $a * 2, 0, 360, $C['ltgray']);
    imageString($im, 1, $sz / 2 - 6, $sz + $a, '5', $C['black']);
    $x = $sz / 2 - 16;
    $y = $sz / 2 - $a;
    imageString($im, 2, $x, $y, "5", $C['ltgray']);
    skygrid($im, $sz, $C);
    $x = $sz / 2 - 16;
    $y = $sz / 2 - 8;
    /* imageString($im, 2, $x, $y, "90", $C['ltgray']); */
    imageString($im, 4, $sz / 2 + 4, 2, 'N', $C['black']);
    imageString($im, 4, $sz / 2 + 4, $sz - 16, 'S', $C['black']);
    imageString($im, 4, 4, $sz / 2 + 4, 'E', $C['black']);
    imageString($im, 4, $sz - 10, $sz / 2 + 4, 'W', $C['black']);
}
コード例 #3
0
$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);
コード例 #4
0
ファイル: Image.php プロジェクト: BGCX261/zibo-svn-to-git
 /**
  * Fills a arc of a circle on the image
  * @param Point $center Point of the circles center
  * @param Dimension $dimension Dimension of the circle
  * @param integer $angleStart 0° is at 3 o'clock and the arc is drawn clockwise
  * @param integer $angleStop
  * @param Color $color
  * @return null
  */
 public function fillArc(Point $center, Dimension $dimension, $angleStart, $angleStop, Color $color, $type = null)
 {
     if (!$type) {
         $type = IMG_ARC_PIE;
     }
     $color = $this->allocateColor($color);
     $x = $center->getX();
     $y = $center->getY();
     $width = $dimension->getWidth();
     $height = $dimension->getHeight();
     imageFilledArc($this->resource, $x, $y, $width, $height, $angleStart, $angleStop, $color, $type);
 }