function leftPointer($image, $xpoint, $ypoint, $colour)
 {
     $black = imagecolorallocate($image, 0x0, 0x0, 0x0);
     $values = array($xpoint + 13, $ypoint - 1, $xpoint + 10, $ypoint - 1, $xpoint + 10, $ypoint - 5, $xpoint + 3, $ypoint + 2, $xpoint + 10, $ypoint + 9, $xpoint + 10, $ypoint + 5, $xpoint + 13, $ypoint + 5);
     imagefilledpolygon($image, $values, 7, $colour);
     imagepolygon($image, $values, 7, $black);
 }
 private function _drawLine($image, $x1, $y1, $x2, $y2)
 {
     $thick = $this->_thickness->getThickness();
     $color = $this->_getDrawColor($image);
     if ($thick == 1) {
         return imageline($image, $x1, $y1, $x2, $y2, $color);
     }
     if ($this->hasTransparency() && $this->_transparency->getTransparency() != ParamTransparency::$minAlpha) {
         $t = $thick / 2 - 0.5;
         if ($x1 == $x2 || $y1 == $y2) {
             return imagefilledrectangle($image, round(min($x1, $x2) - $t), round(min($y1, $y2) - $t), round(max($x1, $x2) + $t), round(max($y1, $y2) + $t), $color);
         }
         $k = ($y2 - $y1) / ($x2 - $x1);
         //y = kx + q
         $a = $t / sqrt(1 + pow($k, 2));
         $points = array(round($x1 - (1 + $k) * $a), round($y1 + (1 - $k) * $a), round($x1 - (1 - $k) * $a), round($y1 - (1 + $k) * $a), round($x2 + (1 + $k) * $a), round($y2 - (1 - $k) * $a), round($x2 + (1 - $k) * $a), round($y2 + (1 + $k) * $a));
         imagefilledpolygon($image, $points, 4, $color);
         imagepolygon($image, $points, 4, $color);
     } else {
         imagesetthickness($image, $thick);
         imageline($image, $x1, $y1, $x2, $y2, $color);
         imagesetthickness($image, 1);
         imagefilledellipse($image, $x1, $y1, $thick, $thick, $color);
         imagefilledellipse($image, $x2, $y2, $thick, $thick, $color);
         imageellipse($image, $x1, $y1, $thick, $thick, $color);
         imageellipse($image, $x2, $y2, $thick, $thick, $color);
     }
 }
 /**
  * Draws this object onto an image
  *
  * @param   img.Image image
  * @return  var
  */
 public function draw($image)
 {
     if ($this->fill) {
         return imagefilledpolygon($image->handle, $this->points, sizeof($this->points) / 2, $this->col->handle);
     } else {
         return imagepolygon($image->handle, $this->points, sizeof($this->points) / 2, $this->col->handle);
     }
 }
Exemple #4
0
 /**
  * Draw polygon.
  * 
  * @param array $points An array containing the polygon's vertices.
  * @param null|array $options
  */
 public function drawPolygon(array $points, array $options = null)
 {
     $this->setOptions($options);
     $colorRgb = Utility::htmlToRgb($this->optionStrokeColor);
     $color = $this->allocateColor($this->Resource, $colorRgb['r'], $colorRgb['g'], $colorRgb['b']);
     imagesetthickness($this->Resource, $this->optionStrokeWidth);
     $numPoints = count($points) / 2;
     imagepolygon($this->Resource, $points, $numPoints, $color);
 }
 protected function renderStroke($image, array $params, $color, $strokeWidth)
 {
     imagesetthickness($image, $strokeWidth);
     if ($params['open']) {
         $this->renderStrokeOpen($image, $params['points'], $color);
         return;
     }
     imagepolygon($image, $params['points'], $params['numpoints'], $color);
 }
 /**
  * @param $gdImage
  * @param $colour
  * @param $point
  * @param $size
  * @param $relative_moves
  */
 public static function wmDrawMarkerPolygon($gdImage, $colour, $point, $size, $relative_moves)
 {
     $points = array();
     foreach ($relative_moves as $move) {
         $point->translate($move[0] * $size, $move[1] * $size);
         $points[] = $point->x;
         $points[] = $point->y;
     }
     imagepolygon($gdImage, $points, count($relative_moves), $colour);
 }
Exemple #7
0
function draw_fill($x1, $y1, $x2, $y2)
{
    global $im, $orange;
    $x1 = transform_x($x1);
    $x2 = transform_x($x2);
    $y1 = transform_y($y1);
    $y2 = transform_y($y2);
    imagepolygon($im, array($x1, $y1, $x2, $y2, $x2, transform_y(0), $x1, transform_y(0)), 4, $orange);
    imagefill($im, ($x1 + $x2) / 2, ($y1 + $y2 + 2 * transform_y(0)) / 4, $orange);
}
Exemple #8
0
 /**
  * Draw polygon on given image
  *
  * @param  Image   $image
  * @param  integer $x
  * @param  integer $y
  * @return boolean
  */
 public function applyToImage(Image $image, $x = 0, $y = 0)
 {
     $background = new Color($this->background);
     imagefilledpolygon($image->getCore(), $this->points, intval(count($this->points) / 2), $background->getInt());
     if ($this->hasBorder()) {
         $border_color = new Color($this->border_color);
         imagesetthickness($image->getCore(), $this->border_width);
         imagepolygon($image->getCore(), $this->points, intval(count($this->points) / 2), $border_color->getInt());
     }
     return true;
 }
Exemple #9
0
 /**
  * Draw polygon on given GD resource
  *
  * @param  resource $resource
  * @param  integer  $x
  * @param  interger $y
  * @return boolean
  */
 private function applyToResource($resource, $x, $y)
 {
     $background = new Color($this->background);
     imagefilledpolygon($resource, $this->points, intval(count($this->points) / 2), $background->getInt());
     if ($this->hasBorder()) {
         $border_color = new Color($this->border_color);
         imagesetthickness($resource, $this->border_width);
         imagepolygon($resource, $this->points, intval(count($this->points) / 2), $border_color->getInt());
     }
     return true;
 }
Exemple #10
0
	function setTitle() {
		$title = $this->title ."";
		$this->drawText($title, 24, 0, 1.9, 32.2, "hitam", "trebuc.ttf");
		imagepolygon($this->gambar, array(
			0,0,
			0,898,
			598,898,
			598,0), 4, $this->getColor("hitam"));
		//tantos
		//$this->drawText("http://tantos.web.id/grafik_barber_johnson/", 10, 0, 5, 0.1, "hitam", "ariali.ttf");
	}
Exemple #11
0
 /**
  * {@inheritdoc}
  */
 protected function execute(array $arguments)
 {
     $success = TRUE;
     if ($arguments['fill_color']) {
         $color = $this->allocateColorFromRgba($arguments['fill_color']);
         $success = imagefilledpolygon($this->getToolkit()->getResource(), $this->getRectangleCorners($arguments['rectangle']), 4, $color);
     }
     if ($success && $arguments['border_color']) {
         $color = $this->allocateColorFromRgba($arguments['border_color']);
         $success = imagepolygon($this->getToolkit()->getResource(), $this->getRectangleCorners($arguments['rectangle']), 4, $color);
     }
     return $success;
 }
Exemple #12
0
 function line($x1, $y1, $x2, $y2, $Color, $Thickness = 1)
 {
     if ($Thickness == 1) {
         return imageline($this->Image, $x1, $y1, $x2, $y2, $Color);
     }
     $t = $Thickness / 2 - 0.5;
     if ($x1 == $x2 || $y1 == $y2) {
         return imagefilledrectangle($this->Image, round(min($x1, $x2) - $t), round(min($y1, $y2) - $t), round(max($x1, $x2) + $t), round(max($y1, $y2) + $t), $color);
     }
     $k = ($y2 - $y1) / ($x2 - $x1);
     //y = kx + q
     $a = $t / sqrt(1 + pow($k, 2));
     $Points = array(round($x1 - (1 + $k) * $a), round($y1 + (1 - $k) * $a), round($x1 - (1 - $k) * $a), round($y1 - (1 + $k) * $a), round($x2 + (1 + $k) * $a), round($y2 - (1 - $k) * $a), round($x2 + (1 - $k) * $a), round($y2 + (1 + $k) * $a));
     imagefilledpolygon($this->Image, $Points, 4, $Color);
     return imagepolygon($this->Image, $Points, 4, $Color);
 }
Exemple #13
0
 function drawDataPoint($image, $x, $y)
 {
     if (DEBUG) {
         print "Drawing data point for {$image} at [{$x}, {$y}] in {$color}.\n";
     }
     $points = polygon_points(array('x' => $x, 'y' => $y), $this->vertices, $this->radius);
     //var_dump(count($points));
     if (DEBUG) {
         var_dump($points);
     }
     if (DEBUG) {
         var_dump($this->vertices);
     }
     imagefilledpolygon($image, $points, $this->vertices, $this->color[0]);
     if (!empty($this->color[1])) {
         imagepolygon($image, $points, $this->vertices, $this->color[1]);
     }
 }
Exemple #14
0
 static function draw(&$image, $color, $param, $name = "line")
 {
     switch ($name) {
         case 'point':
             //像素点
             return imagesetpixel($image, $param[0], $param[1], $color);
         case 'arc':
             //弧(中心点/宽度-高度/起始角度-结束角度(0-360))
             return imagearc($image, $param[0], $param[1], $param[2], $param[3], $param[4], $param[5], $color);
         case 'polygon':
             //多边形$param:各顶点坐标(一维数组),顶点数
             return imagepolygon($image, $param, count($param) / 2, $color);
         default:
             //线(起点/终点)、椭圆(中心点/宽度-高度)、矩形(左顶点/右底点)
             $draw = 'image' . $name;
             //line,ellipse,rectangle
             return $draw($image, $param[0], $param[1], $param[2], $param[3], $color);
     }
 }
Exemple #15
0
 static function draw(&$image, $color, $param, $name = "line")
 {
     //像素点
     if ($name == 'point') {
         return imagesetpixel($image, $param[0], $param[1], $color);
     }
     //线(起点/终点)、椭圆(中心点/宽度-高度)、矩形(左顶点/右底点)
     if ($name == 'line' || $name == 'ellipse' || $name == 'rectangle') {
         $draw = 'image' . $name;
         return $draw($image, $param[0], $param[1], $param[2], $param[3], $color);
     }
     //弧(中心点/宽度-高度/起始角度-结束角度(0-360))
     if ($name == 'arc') {
         return imagearc($image, $param[0], $param[1], $param[2], $param[3], $param[4], $param[5], $color);
     }
     //多边形$param:各顶点坐标(一维数组),顶点数
     if ($name == 'polygon') {
         return imagepolygon($image, $param, count($param) / 2, $color);
     }
 }
Exemple #16
0
 function imagelinethick($image, $x1, $y1, $x2, $y2, $color, $thick = 1)
 {
     /* this way it works well only for orthogonal lines
     			imagesetthickness($image, $thick);
     			return imageline($image, $x1, $y1, $x2, $y2, $color);
     			*/
     if ($thick == 1) {
         return imageline($image, $x1, $y1, $x2, $y2, $color);
     }
     $t = $thick / 2 - 0.5;
     if ($x1 == $x2 || $y1 == $y2) {
         return imagefilledrectangle($image, round(min($x1, $x2) - $t), round(min($y1, $y2) - $t), round(max($x1, $x2) + $t), round(max($y1, $y2) + $t), $color);
     }
     $k = ($y2 - $y1) / ($x2 - $x1);
     //y = kx + q
     $a = $t / sqrt(1 + pow($k, 2));
     $points = array(round($x1 - (1 + $k) * $a), round($y1 + (1 - $k) * $a), round($x1 - (1 - $k) * $a), round($y1 - (1 + $k) * $a), round($x2 + (1 + $k) * $a), round($y2 - (1 - $k) * $a), round($x2 + (1 - $k) * $a), round($y2 + (1 + $k) * $a));
     imagefilledpolygon($image, $points, 4, $color);
     return imagepolygon($image, $points, 4, $color);
 }
 public static function imagelinethick($image, $x1, $y1, $x2, $y2, $color, $thick = 1)
 {
     /* 下面两行只在线段直角相交时好使
        imagesetthickness($image, $thick);
        return imageline($image, $x1, $y1, $x2, $y2, $color);
        */
     if ($thick == 1) {
         return imageline($image, $x1, $y1, $x2, $y2, $color);
     }
     $t = $thick / 2 - 0.5;
     if ($x1 == $x2 || $y1 == $y2) {
         return imagefilledrectangle($image, round(min($x1, $x2) - $t), round(min($y1, $y2) - $t), round(max($x1, $x2) + $t), round(max($y1, $y2) + $t), $color);
     }
     $k = ($y2 - $y1) / ($x2 - $x1);
     //y = kx + q
     $a = $t / sqrt(1 + pow($k, 2));
     $points = array(round($x1 - (1 + $k) * $a), round($y1 + (1 - $k) * $a), round($x1 - (1 - $k) * $a), round($y1 - (1 + $k) * $a), round($x2 + (1 + $k) * $a), round($y2 - (1 - $k) * $a), round($x2 + (1 - $k) * $a), round($y2 + (1 + $k) * $a));
     imagefilledpolygon($image, $points, 4, $color);
     return imagepolygon($image, $points, 4, $color);
 }
function imagelinethick($image, $x1, $y1, $x2, $y2, $color, $thick = 1)
{
    /* de cette manière, ca ne marche bien que pour les lignes orthogonales
       imagesetthickness($image, $thick);
       return imageline($image, $x1, $y1, $x2, $y2, $color);
       */
    if ($thick == 1) {
        return imageline($image, $x1, $y1, $x2, $y2, $color);
    }
    $t = $thick / 2 - 0.5;
    if ($x1 == $x2 || $y1 == $y2) {
        return imagefilledrectangle($image, round(min($x1, $x2) - $t), round(min($y1, $y2) - $t), round(max($x1, $x2) + $t), round(max($y1, $y2) + $t), $color);
    }
    $k = ($y2 - $y1) / ($x2 - $x1);
    //y = kx + q
    $a = $t / sqrt(1 + pow($k, 2));
    $points = array(round($x1 - (1 + $k) * $a), round($y1 + (1 - $k) * $a), round($x1 - (1 - $k) * $a), round($y1 - (1 + $k) * $a), round($x2 + (1 + $k) * $a), round($y2 - (1 - $k) * $a), round($x2 + (1 - $k) * $a), round($y2 + (1 + $k) * $a));
    imagefilledpolygon($image, $points, 4, $color);
    return imagepolygon($image, $points, 4, $color);
}
Exemple #19
0
 public function draw($image)
 {
     if (function_exists('imageantialias')) {
         imageantialias($image->getCore(), true);
     }
     $points = $this->points();
     $count = count($this->points);
     // Create filled polygon
     if (null !== $this->fillColor) {
         list($r, $g, $b, $alpha) = $this->getFillColor()->getRgba();
         $fillColorResource = imagecolorallocatealpha($image->getCore(), $r, $g, $b, Editor::gdAlpha($alpha));
         imagefilledpolygon($image->getCore(), $points, $count, $fillColorResource);
     }
     // Create polygon borders. It will be placed on top of the filled polygon (if present)
     if (0 < $this->getBorderSize() and null !== $this->borderColor) {
         // With border > 0 AND borderColor !== null
         list($r, $g, $b, $alpha) = $this->getBorderColor()->getRgba();
         $borderColorResource = imagecolorallocatealpha($image->getCore(), $r, $g, $b, Editor::gdAlpha($alpha));
         imagepolygon($image->getCore(), $points, $count, $borderColorResource);
     }
     return $image;
 }
Exemple #20
0
 public function render($pDatas)
 {
     $im = @imagecreatetruecolor(300, 300);
     imageantialias($im, true);
     imagefilledrectangle($im, 0, 0, 300, 300, imagecolorallocate($im, 255, 255, 255));
     //Affichage Camenbert
     foreach ($pDatas as $data) {
         if ($data->value == 0) {
             continue;
         }
         $color = imagecolorallocate($im, 255, 0, 0);
         $polygon = iterator_to_array(new \RecursiveIteratorIterator(new \RecursiveArrayIterator($data->polygons)), false);
         imagefilledpolygon($im, $polygon, count($polygon) / 2, $color);
         $black = imagecolorallocate($im, 0, 0, 0);
         imagepolygon($im, $polygon, count($polygon) / 2, $black);
         imagestring($im, '3', $data->center['x'], $data->center['y'], $data->value, $black);
     }
     ob_start();
     imagepng($im);
     $toReturn = ob_get_clean();
     imagedestroy($im);
     return $toReturn;
 }
 protected function drawLegend()
 {
     $leftXShift = 20;
     $units = array('left' => 0, 'right' => 0);
     $legend = new CImageTextTable($this->im, $leftXShift + 10, $this->sizeY + $this->shiftY + $this->legendOffsetY);
     $legend->color = $this->getColor($this->graphtheme['textcolor'], 0);
     $legend->rowheight = 14;
     $legend->fontsize = 9;
     $row = array(array('text' => ''), array('text' => ''), array('text' => S_LST_SMALL, 'align' => 1, 'fontsize' => 9), array('text' => S_MIN_SMALL, 'align' => 1, 'fontsize' => 9), array('text' => S_AVG_SMALL, 'align' => 1, 'fontsize' => 9), array('text' => S_MAX_SMALL, 'align' => 1, 'fontsize' => 9));
     $legend->addRow($row);
     $colNum = $legend->getNumRows();
     $i = $this->type == GRAPH_TYPE_STACKED ? $this->num - 1 : 0;
     while ($i >= 0 && $i < $this->num) {
         if ($this->items[$i]['calc_type'] == GRAPH_ITEM_AGGREGATED) {
             $fnc_name = 'agr(' . $this->items[$i]['periods_cnt'] . ')';
             $color = $this->getColor('HistoryMinMax');
         } else {
             $color = $this->getColor($this->items[$i]['color'], GRAPH_STACKED_ALFA);
             switch ($this->items[$i]['calc_fnc']) {
                 case CALC_FNC_MIN:
                     $fnc_name = S_MIN_SMALL;
                     break;
                 case CALC_FNC_MAX:
                     $fnc_name = S_MAX_SMALL;
                     break;
                 case CALC_FNC_ALL:
                     $fnc_name = S_ALL_SMALL;
                     break;
                 case CALC_FNC_AVG:
                 default:
                     $fnc_name = S_AVG_SMALL;
             }
         }
         $data =& $this->data[$this->items[$i]['itemid']][$this->items[$i]['calc_type']];
         if ($this->itemsHost) {
             $item_caption = $this->items[$i]['description'];
         } else {
             $item_caption = $this->items[$i]['host'] . ': ' . $this->items[$i]['description'];
         }
         if (isset($data) && isset($data['min'])) {
             if ($this->items[$i]['axisside'] == GRAPH_YAXIS_SIDE_LEFT) {
                 $units['left'] = $this->items[$i]['units'];
             } else {
                 $units['right'] = $this->items[$i]['units'];
             }
             $legend->addCell($colNum, array('text' => $item_caption));
             $legend->addCell($colNum, array('text' => '[' . $fnc_name . ']'));
             $legend->addCell($colNum, array('text' => convert_units($this->getLastValue($i), $this->items[$i]['units'], ITEM_CONVERT_NO_UNITS), 'align' => 2));
             $legend->addCell($colNum, array('text' => convert_units(min($data['min']), $this->items[$i]['units'], ITEM_CONVERT_NO_UNITS), 'align' => 2));
             $legend->addCell($colNum, array('text' => convert_units($data['avg_orig'], $this->items[$i]['units'], ITEM_CONVERT_NO_UNITS), 'align' => 2));
             $legend->addCell($colNum, array('text' => convert_units(max($data['max']), $this->items[$i]['units'], ITEM_CONVERT_NO_UNITS), 'align' => 2));
         } else {
             $legend->addCell($colNum, array('text' => $item_caption));
             $legend->addCell($colNum, array('text' => '[ ' . S_NO_DATA_SMALL . ' ]'));
         }
         imagefilledrectangle($this->im, $leftXShift - 5, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY - 10, $leftXShift + 5, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY, $color);
         imagerectangle($this->im, $leftXShift - 5, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY - 10, $leftXShift + 5, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY, $this->getColor('Black'));
         $colNum++;
         if ($this->type == GRAPH_TYPE_STACKED) {
             $i--;
         } else {
             $i++;
         }
     }
     $legend->draw();
     // if graph is small, we are not drawing percent line and trigger legends
     if ($this->sizeY < ZBX_GRAPH_LEGEND_HEIGHT) {
         return true;
     }
     $legend = new CImageTextTable($this->im, $leftXShift + 10, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY);
     $legend->color = $this->getColor($this->graphtheme['textcolor'], 0);
     $legend->rowheight = 14;
     $legend->fontsize = 9;
     // Draw percentile
     if ($this->type == GRAPH_TYPE_NORMAL) {
         foreach ($this->percentile as $side => $percentile) {
             if ($percentile['percent'] > 0 && $percentile['value']) {
                 $percentile['percent'] = (double) $percentile['percent'];
                 $legend->addCell($colNum, array('text' => $percentile['percent'] . 'th percentile: ' . convert_units($percentile['value'], $units[$side]) . '  (' . $side . ')', ITEM_CONVERT_NO_UNITS));
                 if ($side == 'left') {
                     $color = $this->graphtheme['leftpercentilecolor'];
                 } else {
                     $color = $this->graphtheme['rightpercentilecolor'];
                 }
                 imagefilledpolygon($this->im, array($leftXShift + 5, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY, $leftXShift - 5, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY, $leftXShift, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY - 10), 3, $this->getColor($color));
                 imagepolygon($this->im, array($leftXShift + 5, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY, $leftXShift - 5, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY, $leftXShift, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY - 10), 3, $this->getColor('Black No Alpha'));
                 $colNum++;
             }
         }
     }
     $legend->draw();
     $legend = new CImageTextTable($this->im, $leftXShift + 10, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY + 5);
     $legend->color = $this->getColor($this->graphtheme['textcolor'], 0);
     $legend->rowheight = 14;
     $legend->fontsize = 9;
     // Draw triggers
     foreach ($this->triggers as $trigger) {
         imagefilledellipse($this->im, $leftXShift, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY, 10, 10, $this->getColor($trigger['color']));
         imageellipse($this->im, $leftXShift, $this->sizeY + $this->shiftY + 14 * $colNum + $this->legendOffsetY, 10, 10, $this->getColor('Black No Alpha'));
         $legend->addRow(array(array('text' => $trigger['description']), array('text' => $trigger['constant'])));
         $colNum++;
     }
     $legend->draw();
 }
Exemple #22
0
    /**
     * Draw a polygon in the image resource
     *
     * @param array $points
     * @param integer $color
     * @param boolean $filled
     */
    protected function _drawPolygon($points, $color, $filled = true)
    {
        $newPoints = array(
            $points[0][0] + $this->_leftOffset,
            $points[0][1] + $this->_topOffset,
            $points[1][0] + $this->_leftOffset,
            $points[1][1] + $this->_topOffset,
            $points[2][0] + $this->_leftOffset,
            $points[2][1] + $this->_topOffset,
            $points[3][0] + $this->_leftOffset,
            $points[3][1] + $this->_topOffset,
        );

        $allocatedColor = imagecolorallocate(
            $this->_resource,
            ($color & 0xFF0000) >> 16,
            ($color & 0x00FF00) >> 8,
            $color & 0x0000FF
        );

        if ($filled) {
            imagefilledpolygon($this->_resource, $newPoints, 4, $allocatedColor);
        } else {
            imagepolygon($this->_resource, $newPoints, 4, $allocatedColor);
        }
    }
Exemple #23
0
 /**
  * Generate Radar Chart
  *
  * @return	@e void
  */
 protected function _drawRadar()
 {
     //-----------------------------------------
     // Draw Legend & Axes
     //-----------------------------------------
     foreach ($this->data['yaxis'] as $key => $series) {
         $this->legend[$key] = $series['name'];
     }
     if (!$this->_drawLegend()) {
         return false;
     }
     //-----------------------------------------
     // Figure out center position
     //-----------------------------------------
     $xmid = $this->grapharea['x0'] + round(($this->grapharea['x1'] - $this->grapharea['x0']) / 2, 0);
     $ymid = $this->grapharea['y0'] + round(($this->grapharea['y1'] - $this->grapharea['y0']) / 2, 0);
     //-----------------------------------------
     // Figure out size
     //-----------------------------------------
     $maxlabelwidth = 0;
     $maxlabelheight = 0;
     foreach ($this->data['xaxis'] as $label) {
         if ($this->use_ttf) {
             $textsize = imagettfbbox(10, 0, $this->options['font'], $label);
             if ($textsize[2] - $textsize[0] > $maxlabelwidth) {
                 $maxlabelwidth = $textsize[2] - $textsize[0];
             }
             if ($textsize[1] - $textsize[5] > $maxlabelheight) {
                 $maxlabelheight = $textsize[1] - $textsize[5];
             }
         } else {
             $textsize = imagefontwidth($this->fontsize) * strlen($label);
             if ($textsize > $maxlabelwidth) {
                 $maxlabelwidth = $textsize;
             }
             $maxlabelheight = imagefontheight($this->fontsize);
         }
     }
     $lengthx = floor(($this->grapharea['x1'] - $this->grapharea['x0']) / 2 - 5 - $maxlabelwidth);
     $lengthy = floor(($this->grapharea['y1'] - $this->grapharea['y0']) / 2 - 5 - $maxlabelheight);
     $armlength = $lengthx > $lengthy ? $lengthy : $lengthx;
     $numaxes = count($this->data['yaxis'][0]['data']);
     $maxvalue = $this->_getMax($this->data['yaxis']);
     $numticks = $this->options['numticks'] > $maxvalue ? floor($maxvalue) : $this->options['numticks'];
     $maxvalue = ceil($maxvalue / $numticks) * $numticks;
     //-----------------------------------------
     // Allocate text and shadow cols
     //-----------------------------------------
     $textcolor = imagecolorallocate($this->image, hexdec(substr($this->options['titlecolor'], 1, 2)), hexdec(substr($this->options['titlecolor'], 3, 2)), hexdec(substr($this->options['titlecolor'], 5, 2)));
     $shadowcolor = imagecolorallocate($this->image, hexdec(substr($this->options['titleshadow'], 1, 2)), hexdec(substr($this->options['titleshadow'], 3, 2)), hexdec(substr($this->options['titleshadow'], 5, 2)));
     //-----------------------------------------
     // A spider draws a web
     //-----------------------------------------
     $webxy = array();
     $webtick = array();
     $textxy = array();
     for ($i = 0; $i < $numaxes; $i++) {
         $rotation = -90 + round($i * 360 / $numaxes, 0);
         // Web axes
         $webxy[$i * 2] = $xmid + cos(deg2rad($rotation)) * $armlength;
         $webxy[$i * 2 + 1] = $ymid + sin(deg2rad($rotation)) * $armlength;
         imageline($this->image, $xmid, $ymid, $webxy[$i * 2], $webxy[$i * 2 + 1], $this->black);
         // Calculate web tick
         for ($j = 0; $j < $this->options['numticks']; $j++) {
             $webtickxy[$j][$i * 2] = $xmid + cos(deg2rad($rotation)) * (($j + 1) * $armlength / $this->options['numticks']);
             $webtickxy[$j][$i * 2 + 1] = $ymid + sin(deg2rad($rotation)) * (($j + 1) * $armlength / $this->options['numticks']);
         }
         // Calculate the label positions
         $label = $this->data['xaxis'][$i];
         if ($this->use_ttf) {
             $textsize = imagettfbbox(10, 0, $this->options['font'], $label);
             $textwidth = $textsize[4] - $textsize[0];
             $textheight = $textsize[1] - $textsize[5];
         } else {
             $textwidth = imagefontwidth($this->fontsize) * strlen($label);
             $textheight = imagefontheight($this->fontsize);
         }
         if ($rotation > -90 && $rotation < 90) {
             $textxy[] = $webxy[$i * 2] + 5;
             $textxy[] = $webxy[$i * 2 + 1] + floor($textheight / 2);
         } elseif ($rotation == -90) {
             $textxy[] = $webxy[$i * 2] - floor($textwidth / 2);
             $textxy[] = $webxy[$i * 2 + 1] - 5;
         } elseif ($rotation == 90) {
             $textxy[] = $webxy[$i * 2] - floor($textwidth / 2);
             $textxy[] = $webxy[$i * 2 + 1] + 5 + $textheight;
         } else {
             $textxy[] = $webxy[$i * 2] - 5 - $textwidth;
             $textxy[] = $webxy[$i * 2 + 1] + floor($textheight / 2);
         }
         // Draw the labels
         if ($this->use_ttf) {
             imagettftext($this->image, "10", 0, $textxy[$i * 2] + 1, $textxy[$i * 2 + 1] + 1, $shadowcolor, $this->options['font'], $label);
             imagettftext($this->image, "10", 0, $textxy[$i * 2], $textxy[$i * 2 + 1], $textcolor, $this->options['font'], $label);
         } else {
             imagestring($this->image, $this->fontsize, $textxy[$i * 2] + 1, $textxy[$i * 2 + 1] + 1 - imagefontheight($this->fontsize), $label, $shadowcolor);
             imagestring($this->image, $this->fontsize, $textxy[$i * 2], $textxy[$i * 2 + 1] - imagefontheight($this->fontsize), $label, $textcolor);
         }
     }
     //-----------------------------------------
     // Draw the web lines
     //-----------------------------------------
     foreach ($webtickxy as $tickxy) {
         imagepolygon($this->image, $tickxy, $numaxes, $this->black);
     }
     //-----------------------------------------
     // Draw the axes value text
     //-----------------------------------------
     $numticks = $this->options['numticks'] > $maxvalue ? floor($maxvalue) : $this->options['numticks'];
     $tick = $maxvalue / $numticks;
     for ($j = 0; $j < $this->options['numticks']; $j++) {
         $value = ($j + 1) * $tick;
         if ($this->use_ttf) {
             $textsize = imagettfbbox(10, 0, $this->options['font'], $value);
             $textheight = $textsize[1] - $textsize[5];
             imagettftext($this->image, "10", 0, $webtickxy[$j][0] + 6, $webtickxy[$j][1] + floor($textheight / 2) + 1, $shadowcolor, $this->options['font'], $value);
             imagettftext($this->image, "10", 0, $webtickxy[$j][0] + 5, $webtickxy[$j][1] + floor($textheight / 2), $textcolor, $this->options['font'], $value);
         } else {
             imagestring($this->image, $this->fontsize, $webtickxy[$j][0] + 6, $webtickxy[$j][1] - floor(imagefontheight($this->fontsize) / 2) + 1, $value, $shadowcolor);
             imagestring($this->image, $this->fontsize, $webtickxy[$j][0] + 5, $webtickxy[$j][1] - floor(imagefontheight($this->fontsize) / 2), $value, $textcolor);
         }
     }
     //-----------------------------------------
     // Draw the series
     //-----------------------------------------
     $numseries = count($this->data['yaxis']);
     for ($ci = 0; $ci < $numseries; $ci++) {
         if (!isset($this->color[$ci])) {
             $this->color[$ci] = explode(",", $this->_getSliceColor($this->data['yaxis'][$ci]['color']));
         }
         $linecolor = ImageColorAllocate($this->image, $this->color[$ci][0], $this->color[$ci][1], $this->color[$ci][2]);
         $dotcolor = imagecolorallocate($this->image, $this->color[$ci][0], $this->color[$ci][1], $this->color[$ci][2]);
         $dotshadowcolor = imagecolorallocate($this->image, $this->color[$ci][0] - 50 < 0 ? 0 : $this->color[$ci][0] - 50, $this->color[$ci][1] - 50 < 0 ? 0 : $this->color[$ci][1] - 50, $this->color[$ci][2] - 50 < 0 ? 0 : $this->color[$ci][2] - 50);
         //-----------------------------------------
         // Get the x and y's for the lines
         //-----------------------------------------
         $linesxy = array();
         $lineshadowxy = array();
         $textxy = array();
         for ($i = 0; $i < $numaxes; $i++) {
             $value = $this->data['yaxis'][$ci]['data'][$i];
             $rotation = -90 + round($i * 360 / $numaxes, 0);
             $linesxy[$i * 2] = $xmid + cos(deg2rad($rotation)) * floor($value / $maxvalue * $armlength);
             $linesxy[$i * 2 + 1] = $ymid + sin(deg2rad($rotation)) * floor($value / $maxvalue * $armlength);
             $lineshadowxy[$i * 2] = $linesxy[$i * 2] + 1;
             $lineshadowxy[$i * 2 + 1] = $linesxy[$i * 2 + 1] + 1;
             if ($this->options['showdatalabels']) {
                 // Calculate the datalabel positions
                 $textxy[$i * 2] = $xmid + cos(deg2rad($rotation)) * floor($value / $maxvalue * $armlength + 5);
                 $textxy[$i * 2 + 1] = $ymid + sin(deg2rad($rotation)) * floor($value / $maxvalue * $armlength + 5);
                 if ($this->use_ttf) {
                     $textsize = imagettfbbox(10, 0, $this->options['font'], $value);
                     $textwidth = $textsize[4] - $textsize[0];
                     $textheight = $textsize[1] - $textsize[5];
                 } else {
                     $textwidth = imagefontwidth($this->fontsize) * strlen($value);
                     $textheight = imagefontheight($this->fontsize);
                 }
                 if ($rotation > -90 && $rotation < 90) {
                     $textxy[$i * 2] = $textxy[$i * 2] + 5;
                     $textxy[$i * 2 + 1] = $textxy[$i * 2 + 1] + floor($textheight / 2);
                 } elseif ($rotation == -90) {
                     $textxy[$i * 2] = $textxy[$i * 2] - floor($textwidth / 2);
                     $textxy[$i * 2 + 1] = $textxy[$i * 2 + 1] - 5;
                 } elseif ($rotation == 90) {
                     $textxy[$i * 2] = $textxy[$i * 2] - floor($textwidth / 2);
                     $textxy[$i * 2 + 1] = $textxy[$i * 2 + 1] + 5 + $textheight;
                 } else {
                     $textxy[$i * 2] = $textxy[$i * 2] - 5 - $textwidth;
                     $textxy[$i * 2 + 1] = $textxy[$i * 2 + 1] + floor($textheight / 2);
                 }
             }
         }
         //-----------------------------------------
         // Draw the lines, dots and text
         //-----------------------------------------
         imagepolygon($this->image, $linesxy, $numaxes, $linecolor);
         imagepolygon($this->image, $lineshadowxy, $numaxes, $dotshadowcolor);
         $valuecolor = ImageColorAllocate($this->image, hexdec(substr($this->options['textcolor'], 1, 2)), hexdec(substr($this->options['textcolor'], 3, 2)), hexdec(substr($this->options['textcolor'], 5, 2)));
         $valshadecolor = imagecolorallocate($this->image, $this->color[$ci][0] - 50 < 0 ? 0 : $this->color[$ci][0] - 50, $this->color[$ci][1] - 50 < 0 ? 0 : $this->color[$ci][1] - 50, $this->color[$ci][2] - 50 < 0 ? 0 : $this->color[$ci][2] - 50);
         for ($i = 0; $i < $numaxes; $i++) {
             imagefilledellipse($this->image, $linesxy[$i * 2] + 1, $linesxy[$i * 2 + 1] + 1, 7, 7, $dotshadowcolor);
             imagefilledellipse($this->image, $linesxy[$i * 2], $linesxy[$i * 2 + 1], 7, 7, $dotcolor);
             if ($this->options['showdatalabels']) {
                 $value = $this->data['yaxis'][$ci]['data'][$i];
                 if ($this->use_ttf) {
                     imagettftext($this->image, "10", 0, $textxy[$i * 2] - 1, $textxy[$i * 2 + 1] - 1, $valshadecolor, $this->options['font'], $value);
                     imagettftext($this->image, "10", 0, $textxy[$i * 2] + 1, $textxy[$i * 2 + 1] + 1, $valshadecolor, $this->options['font'], $value);
                     imagettftext($this->image, "10", 0, $textxy[$i * 2] + 2, $textxy[$i * 2 + 1] + 2, $valshadecolor, $this->options['font'], $value);
                     imagettftext($this->image, "10", 0, $textxy[$i * 2], $textxy[$i * 2 + 1], $valuecolor, $this->options['font'], $value);
                 } else {
                     imagestring($this->image, $this->fontsize, $textxy[$i * 2] - 1, $textxy[$i * 2 + 1] - 1 - imagefontheight($this->fontsize), $label, $valshadecolor);
                     imagestring($this->image, $this->fontsize, $textxy[$i * 2] + 1, $textxy[$i * 2 + 1] + 1 - imagefontheight($this->fontsize), $label, $valshadecolor);
                     imagestring($this->image, $this->fontsize, $textxy[$i * 2] + 2, $textxy[$i * 2 + 1] + 2 - imagefontheight($this->fontsize), $label, $valshadecolor);
                     imagestring($this->image, $this->fontsize, $textxy[$i * 2], $textxy[$i * 2 + 1] - imagefontheight($this->fontsize), $label, $valuecolor);
                 }
             }
         }
         imagecolordeallocate($this->image, $linecolor);
         imagecolordeallocate($this->image, $dotcolor);
         imagecolordeallocate($this->image, $dotshadowcolor);
         imagecolordeallocate($this->image, $valshadecolor);
         imagecolordeallocate($this->image, $valuecolor);
     }
     return true;
 }
             // fill
             imagesettile($target_image, $fill_image);
             imagesetthickness($target_image, 2);
             imagefilledpolygon($target_image, $points, count($points) / 2, IMG_COLOR_TILED);
             // look mom, Decimal System!
             $labelCharCount = 1 + floor(log10(max(1, $pNum)));
             // label BG + TXT
             imagefilledrectangle($target_image, mapCoord($px) + 2, mapCoord($py) + 2, mapCoord($px) + 2 + imagefontwidth(1) * $labelCharCount, mapCoord($py) + 2 + imagefontheight(1), $colBg);
             imagestring($target_image, 1, mapCoord($px) + 2, mapCoord($py) + 2, $pNum, $colTxt);
             // outline line
             imagepolygon($target_image, $points, count($points) / 2, $colShape);
         } else {
             // other polygons describes "holes" in shape
             imagesetthickness($target_image, 2);
             imagefilledpolygon($target_image, $points, count($points) / 2, $colBg);
             imagepolygon($target_image, $points, count($points) / 2, $colShape);
             imagestring($target_image, 1, mapCoord($px) + 2, mapCoord($py) + 2, $pNum, $colShape);
         }
         $subShape++;
     }
     imagedestroy($fill_image);
     $pNum++;
     break;
 case QR_AREA_POINT:
     $symb = array_shift($path);
     while (count($path) > 0) {
         $px = array_shift($path);
         $py = array_shift($path);
         imagefilledrectangle($target_image, mapCoord($px), mapCoord($py), mapCoord($px + 1) - 1, mapCoord($py + 1) - 1, $colPix);
     }
     break;
// Back panel
imagerectangle($image, $padding + $leftTab + $z, $padding + $z * 2, $padding + $leftTab + $z + $x, $padding + $z * 2 + $y, $borderColour);
// Side panel
imagerectangle($image, $padding + $leftTab + $z + $x, $padding + $z * 2, $padding + $leftTab + $z + $x + $z, $padding + $z * 2 + $y, $borderColour);
// Front panel
imagerectangle($image, $padding + $leftTab + $z + $z + $x, $padding + $z * 2, $padding + $leftTab + $z + $z + 2 * $x, $padding + $z * 2 + $y, $borderColour);
// Top panel
imagerectangle($image, $padding + $leftTab + $z, $padding + $z, $padding + $leftTab + $z + $x, $padding + $z * 2, $borderColour);
// Bottom panel
imagerectangle($image, $padding + $leftTab + $z, $padding + $z * 2 + $y, $padding + $leftTab + $z + $x, $padding + $z * 3 + $y, $borderColour);
// Top flap
imagearc($image, $padding + $leftTab + $z + $z, $padding + $z, $z * 2, $z * 2, 180, 270, $borderColour);
imagearc($image, $padding + $leftTab + $x, $padding + $z, $z * 2, $z * 2, 270, 360, $borderColour);
imageline($image, $padding + $leftTab + $z + $z, $padding, $padding + $leftTab + $x, $padding, $borderColour);
// left flap
imagepolygon($image, array($padding + $leftTab, $padding + $z * 2, $padding + $leftTab, $padding + $z * 2 + $y, $padding, $padding + $z * 2 + 0.9 * $y, $padding, $padding + $z * 2 + 0.1 * $y), 4, $borderColour);
// top flap
imagepolygon($image, array($padding + $leftTab + 0.1 * $z, $padding + $z, $padding + $leftTab + 0.9 * $z, $padding + $z, $padding + $leftTab + $z, $padding + $z * 2, $padding + $leftTab, $padding + $z * 2), 4, $borderColour);
// top flap
imagepolygon($image, array($padding + $leftTab + $x + 1.1 * $z, $padding + $z, $padding + $leftTab + $x + 1.9 * $z, $padding + $z, $padding + $leftTab + $x + 2 * $z, $padding + $z * 2, $padding + $leftTab + $x + $z, $padding + $z * 2), 4, $borderColour);
// bottom flap
imagepolygon($image, array($padding + $leftTab + $z + 0.1 * $x, $padding + $y + 4 * $z, $padding + $leftTab + $z + 0.9 * $x, $padding + $y + 4 * $z, $padding + $leftTab + $z + $x, $padding + $y + 3 * $z, $padding + $leftTab + $z, $padding + $y + 3 * $z), 4, $borderColour);
// bottom flap
imagepolygon($image, array($padding + $leftTab + 0.1 * $z, $padding + $y + 3 * $z, $padding + $leftTab + 0.9 * $z, $padding + $y + 3 * $z, $padding + $leftTab + $z, $padding + $y + 2 * $z, $padding + $leftTab, $padding + $y + 2 * $z), 4, $borderColour);
// bottom flap
imagepolygon($image, array($padding + $leftTab + $x + 1.1 * $z, $padding + $y + 3 * $z, $padding + $leftTab + $x + 1.9 * $z, $padding + $y + 3 * $z, $padding + $leftTab + $x + 2 * $z, $padding + $y + 2 * $z, $padding + $leftTab + $x + $z, $padding + $y + 2 * $z), 4, $borderColour);
// finger hole
imagearc($image, $padding + $leftTab + $z + $x + $z + $x / 2, $padding + $z + $z, $x / 4, $x / 4, 0, 180, $borderColour);
header("Content-Type: image/png");
header('Content-Disposition: attachment; filename="tuckbox-' . $_POST['x'] . '-' . $_POST['y'] . '-' . $_POST['z'] . '.png"');
imagepng($image);
Exemple #26
0
 /**
  * Draws a polygon
  *
  * The polygon is formed by joining all the points stored in the $points
  * array.  $points has the following structure:
  * <code>
  * array(0 => x1,
  *       1 => y1,
  *       2 => x2,
  *       3 => y2,
  *       ...
  *       );
  * </code>
  *
  * See {@link Style::munge_color()} for the format of the color array.
  * See {@link Cpdf::setLineStyle()} for a description of the $style
  * parameter (aka dash)   
  *
  * @param array $points
  * @param array $color
  * @param float $width
  * @param array $style
  * @param bool  $fill  Fills the polygon if true
  */
 function polygon($points, $color, $width = null, $style = null, $fill = false)
 {
     // Scale each point by the AA factor
     foreach (array_keys($points) as $i) {
         $points[$i] *= $this->_aa_factor;
     }
     $c = $this->_allocate_color($color);
     // Convert the style array if required
     if (!is_null($style) && !$fill) {
         $gd_style = array();
         foreach ($style as $length) {
             for ($i = 0; $i < $length; $i++) {
                 $gd_style[] = $c;
             }
         }
         imagesetstyle($this->_img, $gd_style);
         $c = IMG_COLOR_STYLED;
     }
     imagesetthickness($this->_img, $width);
     if ($fill) {
         imagefilledpolygon($this->_img, $points, count($points) / 2, $c);
     } else {
         imagepolygon($this->_img, $points, count($points) / 2, $c);
     }
 }
Exemple #27
0
function imgFolder()
{
    $a = array(18, 24, 38, 24, 43, 29, 76, 29, 76, 70, 18, 70);
    if (function_exists('imagecreatetruecolor')) {
        $img = imagecreatetruecolor(94, 94);
        $black = imagecolorclosest($img, 0, 0, 0);
        $yellow = imagecolorclosest($img, 250, 240, 0);
        $white = imagecolorclosest($img, 255, 255, 255);
    } else {
        $img = imagecreate(94, 94);
        $black = imagecolorallocate($img, 0, 0, 0);
        $yellow = imagecolorallocate($img, 250, 240, 0);
        $white = imagecolorallocate($img, 255, 255, 255);
    }
    imagefilledrectangle($img, 0, 0, 94, 94, $white);
    if (function_exists('imagesetthickness')) {
        imagesetthickness($img, 1);
    }
    imagefilledpolygon($img, $a, 6, $yellow);
    imagepolygon($img, $a, 6, $black);
    imageline($img, 40, 32, 76, 32, $black);
    imageline($img, 18, 34, 34, 34, $black);
    imageline($img, 34, 34, 40, 32, $black);
    return $img;
}
Exemple #28
0
function addScribble($image, $width, $height)
{
    for ($i = 0; $i < 8; $i++) {
        $color = imagecolorallocate($image, rand(100, 180), rand(100, 180), rand(100, 180));
        $points = array();
        for ($j = 1; $j < rand(5, 10); $j++) {
            $points[] = rand(2 * (20 * ($i + 1)), 2 * (50 * ($i + 1)));
            $points[] = rand(30, $height + 30);
        }
        imagesetthickness($image, rand(2, 6));
        imagepolygon($image, $points, intval(sizeof($points) / 2), $color);
        imagecolordeallocate($image, $color);
    }
}
 /**
  * plot the gridlines
  * @access private
  */
 function _plotGridLines(&$img, $scanleft, $scanbottom, $scanright, $scantop, $bottom, $left, $pre = false)
 {
     static $gridcol, $gridcol2, $text1, $text2;
     //these are static so they can be assigned before the images are added
     global $CONF;
     if ($pre) {
         if ($this->pixels_per_km >= 40) {
             $gridcol = imagecolorallocate($img, 89, 126, 118);
             $gridcol2 = imagecolorallocate($img, 60, 205, 252);
             //plot the individual lines
             for ($i = 0; $i < $this->image_w; $i += $this->pixels_per_km) {
                 imageline($img, $i, 0, $i, $this->image_w, $gridcol2);
             }
             for ($j = 0; $j < $this->image_h; $j += $this->pixels_per_km) {
                 imageline($img, 0, $j, $this->image_h, $j, $gridcol2);
             }
         } else {
             if (0 && $this->pixels_per_km == 4) {
                 //todo : currently disabled as doesnt work when the map straddles the Irish Sea :-(
                 // needs to only draw lines within the manually defined boundary, but cant (yet) think of a alogorim ???
                 //could enable for when map is wholely one grid, but a bodge and result inconsistent...
                 $gridcol = imagecolorallocate($img, 89, 126, 118);
                 $gridcol2 = imagecolorallocate($img, 60, 205, 252);
                 if (!$this->reference_index) {
                     $this->getGridRef(-1, -1);
                 }
                 //plot the individual lines
                 $s = ($left - $CONF['origins'][$this->reference_index][0]) % 10;
                 for ($i = $s * $this->pixels_per_km; $i < $this->image_w; $i += $this->pixels_per_km * 10) {
                     imageline($img, $i, 0, $i, $this->image_w, $gridcol2);
                 }
                 $s = ($bottom - $CONF['origins'][$this->reference_index][1]) % 10;
                 for ($j = $s * $this->pixels_per_km; $j < $this->image_h; $j += $this->pixels_per_km * 10) {
                     imageline($img, 0, $j, $this->image_h, $j, $gridcol2);
                 }
             } else {
                 $gridcol = imagecolorallocate($img, 109, 186, 178);
             }
         }
         if ($this->pixels_per_km < 1 || $this->pixels_per_km >= 40) {
             $text1 = imagecolorallocate($img, 255, 255, 255);
             $text2 = imagecolorallocate($img, 0, 64, 0);
         } else {
             $text1 = $gridcol;
         }
         return;
     }
     $db =& $this->_getDB();
     //TODO  - HARD CODED VALUES!!
     $width = 100;
     $scanleft -= $width;
     $scanbottom -= $width;
     $rectangle = "'POLYGON(({$scanleft} {$scanbottom},{$scanright} {$scanbottom},{$scanright} {$scantop},{$scanleft} {$scantop},{$scanleft} {$scanbottom}))'";
     $sql = "select * from gridprefix where " . "CONTAINS( GeomFromText({$rectangle}),\tpoint_origin_xy) " . "and landcount>0";
     $recordSet =& $db->Execute($sql);
     while (!$recordSet->EOF) {
         $origin_x = $recordSet->fields['origin_x'];
         $origin_y = $recordSet->fields['origin_y'];
         $w = $recordSet->fields['width'];
         $h = $recordSet->fields['height'];
         $labelminwidth = $recordSet->fields['labelminwidth'];
         //get polygon of boundary relative to corner of square
         if (strlen($recordSet->fields['boundary'])) {
             $polykm = explode(',', $recordSet->fields['boundary']);
             $labelkm = explode(',', $recordSet->fields['labelcentre']);
         } else {
             $polykm = array(0, 0, 0, 100, 100, 100, 100, 0);
             $labelkm = array(50, 50);
         }
         //now convert km to pixels
         $poly = array();
         $label = array();
         $pts = count($polykm) / 2;
         for ($i = 0; $i < $pts; $i++) {
             $poly[$i * 2] = round(($polykm[$i * 2] + $origin_x - $left) * $this->pixels_per_km);
             $poly[$i * 2 + 1] = round($this->image_h - ($polykm[$i * 2 + 1] + $origin_y - $bottom) * $this->pixels_per_km);
         }
         $labelx = round(($labelkm[0] + $origin_x - $left) * $this->pixels_per_km);
         $labely = round($this->image_h - ($labelkm[1] + $origin_y - $bottom) * $this->pixels_per_km);
         imagepolygon($img, $poly, $pts, $gridcol);
         if ($this->pixels_per_km >= 0.3 && 100 * $this->pixels_per_km >= $labelminwidth) {
             //font size 1= 4x6
             //font size 2= 6x8 normal
             //font size 3= 6x8 bold
             //font size 4= 7x10 normal
             //font size 5= 8x10 bold
             if ($this->pixels_per_km >= 1) {
                 $font = 5;
             } else {
                 $font = 3;
             }
             $text = $recordSet->fields['prefix'];
             $txtw = imagefontwidth($font) * strlen($text);
             $txth = imagefontheight($font);
             $txtx = round($labelx - $txtw / 2);
             $txty = round($labely - $txth / 2);
             if ($this->pixels_per_km < 1) {
                 imagestring($img, $font, $txtx + 1, $txty + 1, $text, $text2);
                 imagestring($img, $font, $txtx, $txty, $text, $text1);
             } else {
                 imagestring($img, $font, $txtx, $txty, $text, $text1);
             }
             $thisrect = array($txtx, $txty, $txtx + $txtw, $txty + $txth);
             array_push($this->labels, $thisrect);
             if ($_GET['d']) {
                 print "{$text}";
                 var_dump($thisrect);
                 print "<BR>";
             }
         }
         $recordSet->MoveNext();
     }
     $recordSet->Close();
     //plot the number labels
     if ($this->pixels_per_km >= 40) {
         $gridref = $this->getGridRef(0, $this->image_h);
         //origin of image is tl, map is bl
         if (preg_match('/^([A-Z]{1,3})(\\d\\d)(\\d\\d)$/', $gridref, $matches)) {
             $gridsquare = $matches[1];
             $eastings = $matches[2];
             $northings = $matches[3];
             $gran = 10;
             $font = 3;
             $me = imagefontwidth($font);
             $mn = floor(imagefontheight($font) / 2);
             $e5 = floor($eastings / $gran) * $gran;
             if ($e5 < $eastings) {
                 $e5 += $gran;
             }
             $n5 = floor($northings / $gran) * $gran;
             if ($n5 < $northings) {
                 $n5 += $gran;
             }
             $ed = ($e5 - $eastings) * $this->pixels_per_km + $this->pixels_per_km / 2 - $me;
             $nd = $this->image_h - ($n5 - $northings) * $this->pixels_per_km - $this->pixels_per_km / 2 - $mn;
             $e = $eastings;
             for ($i = 1 - $me; $i <= $this->image_w; $i += $this->pixels_per_km) {
                 imagestring($img, $font, $i + 1, $nd + 1, $e, $text2);
                 imagestring($img, $font, $i, $nd, $e, $text1);
                 $e = sprintf("%02d", ($e + 1) % 100);
             }
             $n = $northings;
             for ($j = $this->image_h - $mn; $j >= 0 - $mn; $j -= $this->pixels_per_km) {
                 imagestring($img, $font, $ed + 1, $j + 1, $n, $text2);
                 imagestring($img, $font, $ed, $j, $n, $text1);
                 $n = sprintf("%02d", ($n + 1) % 100);
             }
         }
     }
 }
Exemple #30
0
	/**
	 * Draw a polygon
	 *
	 * @param $color Polygon color
	 * @param Polygon A polygon
	 */
	 function polygon($color, &$polygon) {
		
		switch($polygon->getStyle()) {
		
			case POLYGON_SOLID :
				$thickness = $line->getThickness();
				$this->startThickness($thickness);
				$points = $this->getPolygonPoints($polygon);
				$rgb = $color->getColor($this->resource);
				imagepolygon($this->resource, $points, $polygon->count(), $rgb);
				$this->stopThickness($thickness);
				break;
				
			default :
			
				if($polygon->count() > 1) {
				
					$prev = $polygon->get(0);
					
					$line = new awLine;
					$line->setStyle($polygon->getStyle());
					$line->setThickness($polygon->getThickness());
					
					for($i = 1; $i < $polygon->count(); $i++) {
						$current = $polygon->get($i);
						$line->setLocation($prev, $current);
						$this->line($color, $line);
						$prev = $current;
					}
					
				}
		
		}
		
	}