public function draw()
 {
     $start_time = microtime(true);
     set_image_header();
     $this->selectData();
     $this->shiftY = 30;
     $this->shiftYLegend = 20;
     $this->shiftXleft = 10;
     $this->shiftXright = 0;
     $this->fullSizeX = $this->sizeX;
     $this->fullSizeY = $this->sizeY;
     if ($this->sizeX < 300 || $this->sizeY < 200) {
         $this->showLegend(0);
     }
     if ($this->drawLegend == 1) {
         $this->sizeX -= $this->shiftXleft + $this->shiftXright + $this->shiftlegendright;
         $this->sizeY -= $this->shiftY + $this->shiftYLegend + 12 * $this->num + 8;
     } else {
         $this->sizeX -= $this->shiftXleft * 2;
         $this->sizeY -= $this->shiftY * 2;
     }
     $this->sizeX = min($this->sizeX, $this->sizeY);
     $this->sizeY = min($this->sizeX, $this->sizeY);
     $this->calc3dheight($this->sizeY);
     $this->exploderad = (int) $this->sizeX / 100;
     $this->exploderad3d = (int) $this->sizeX / 60;
     if (function_exists('ImageColorExactAlpha') && function_exists('ImageCreateTrueColor') && @imagecreatetruecolor(1, 1)) {
         $this->im = imagecreatetruecolor($this->fullSizeX, $this->fullSizeY);
     } else {
         $this->im = imagecreate($this->fullSizeX, $this->fullSizeY);
     }
     $this->initColors();
     $this->drawRectangle();
     $this->drawHeader();
     // for each metric
     for ($item = 0; $item < $this->num; $item++) {
         $data =& $this->data[$this->items[$item]['itemid']][$this->items[$item]['calc_type']];
         if (!isset($data)) {
             continue;
         }
         $calc_fnc = $this->items[$item]['calc_fnc'];
         switch ($calc_fnc) {
             case CALC_FNC_MAX:
                 $values[$item] = abs($data->max);
                 break;
             case CALC_FNC_MIN:
                 $values[$item] = abs($data->min);
                 break;
             case CALC_FNC_AVG:
                 $values[$item] = abs($data->avg);
                 break;
             case CALC_FNC_LST:
                 $values[$item] = abs($data->lst);
                 break;
         }
     }
     switch ($this->type) {
         case GRAPH_TYPE_EXPLODED:
             $this->drawElementPie($values);
             break;
         case GRAPH_TYPE_3D:
             $this->drawElementPie3D($values);
             break;
         case GRAPH_TYPE_3D_EXPLODED:
             $this->drawElementPie3D($values);
             break;
         default:
             $this->drawElementPie($values);
             break;
     }
     $this->drawLogo();
     if ($this->drawLegend == 1) {
         $this->drawLegend();
     }
     $str = sprintf('%0.2f', microtime(true) - $start_time);
     $str = _s('Data from %1$s. Generated in %2$s sec.', $this->dataFrom, $str);
     $strSize = imageTextSize(6, 0, $str);
     imageText($this->im, 6, 0, $this->fullSizeX - $strSize['width'] - 5, $this->fullSizeY - 5, $this->getColor('Gray'), $str);
     unset($this->items, $this->data);
     imageOut($this->im);
 }
Пример #2
0
 protected function paintGrid()
 {
     $size = $this->options['grid']['size'];
     if (empty($size)) {
         return;
     }
     $width = $this->canvas->getWidth();
     $height = $this->canvas->getHeight();
     $maxSize = max($width, $height);
     $dims = imageTextSize(8, 0, '00');
     for ($xy = $size; $xy < $maxSize; $xy += $size) {
         if ($xy < $width) {
             $this->canvas->drawLine($xy, 0, $xy, $height, $this->options['grid']['color'], MAP_LINK_DRAWTYPE_DASHED_LINE);
             $this->canvas->drawText(8, 0, $xy + 3, $dims['height'] + 3, $this->options['grid']['color'], $xy);
         }
         if ($xy < $height) {
             $this->canvas->drawLine(0, $xy, $width, $xy, $this->options['grid']['color'], MAP_LINK_DRAWTYPE_DASHED_LINE);
             $this->canvas->drawText(8, 0, 3, $xy + $dims['height'] + 3, $this->options['grid']['color'], $xy);
         }
     }
     $this->canvas->drawText(8, 0, 2, $dims['height'] + 3, 'black', 'Y X:');
 }
Пример #3
0
 public function drawHeader()
 {
     if (!isset($this->header)) {
         $str = $this->items[0]['host'] . ': ' . $this->items[0]['description'];
     } else {
         $str = $this->header;
     }
     $str .= $this->period2str($this->period);
     $fontnum = 11;
     if ($this->sizeX < 500 && ($this->type == GRAPH_TYPE_NORMAL || $this->type == GRAPH_TYPE_BAR)) {
         $fontnum = 8;
     }
     $dims = imageTextSize($fontnum, 0, $str);
     $x = $this->fullSizeX / 2 - $dims['width'] / 2;
     imagetext($this->im, $fontnum, 0, $x, 24, $this->getColor($this->graphtheme['textcolor'], 0), $str);
 }
Пример #4
0
 public function draw()
 {
     $start_time = microtime(true);
     set_image_header();
     $this->selectData();
     if (isset($this->axis_valuetype[GRAPH_YAXIS_SIDE_RIGHT])) {
         $sides[] = GRAPH_YAXIS_SIDE_RIGHT;
     }
     if (isset($this->axis_valuetype[GRAPH_YAXIS_SIDE_LEFT]) || !isset($sides)) {
         $sides[] = GRAPH_YAXIS_SIDE_LEFT;
     }
     foreach ($sides as $graphSide) {
         $this->m_minY[$graphSide] = $this->calculateMinY($graphSide);
         $this->m_maxY[$graphSide] = $this->calculateMaxY($graphSide);
         if ($this->m_minY[$graphSide] === null) {
             $this->m_minY[$graphSide] = 0;
         }
         if ($this->m_maxY[$graphSide] === null) {
             $this->m_maxY[$graphSide] = 1;
         }
         if ($this->m_minY[$graphSide] == $this->m_maxY[$graphSide]) {
             if ($this->graphOrientation[$graphSide] == '-') {
                 $this->m_maxY[$graphSide] = 0;
             } elseif ($this->m_minY[$graphSide] == 0) {
                 $this->m_maxY[$graphSide] = 1;
             } else {
                 $this->m_minY[$graphSide] = 0;
             }
         } elseif ($this->m_minY[$graphSide] > $this->m_maxY[$graphSide]) {
             if ($this->graphOrientation[$graphSide] == '-') {
                 $this->m_minY[$graphSide] = bcmul($this->m_maxY[$graphSide], 0.2);
             } else {
                 $this->m_minY[$graphSide] = 0;
             }
         }
         // If max Y-scale bigger min Y-scale only for 10% or less, then we don't allow Y-scale duplicate
         if ($this->m_maxY[$graphSide] && $this->m_minY[$graphSide]) {
             if ($this->m_minY[$graphSide] < 0) {
                 $absMinY = bcmul($this->m_minY[$graphSide], '-1');
             } else {
                 $absMinY = $this->m_minY[$graphSide];
             }
             if ($this->m_maxY[$graphSide] < 0) {
                 $absMaxY = bcmul($this->m_maxY[$graphSide], '-1');
             } else {
                 $absMaxY = $this->m_maxY[$graphSide];
             }
             if ($absMaxY < $absMinY) {
                 $oldAbMaxY = $absMaxY;
                 $absMaxY = $absMinY;
                 $absMinY = $oldAbMaxY;
             }
             if (bcdiv(bcsub($absMaxY, $absMinY), $absMaxY) <= 0.1) {
                 if ($this->m_minY[$graphSide] > 0) {
                     $this->m_minY[$graphSide] = bcmul($this->m_minY[$graphSide], 0.95);
                 } else {
                     $this->m_minY[$graphSide] = bcmul($this->m_minY[$graphSide], 1.05);
                 }
                 if ($this->m_maxY[$graphSide] > 0) {
                     $this->m_maxY[$graphSide] = bcmul($this->m_maxY[$graphSide], 1.05);
                 } else {
                     $this->m_maxY[$graphSide] = bcmul($this->m_maxY[$graphSide], 0.95);
                 }
             }
         }
     }
     $this->calcMinMaxInterval();
     $this->updateShifts();
     $this->calcTriggers();
     $this->calcZero();
     $this->calcPercentile();
     $this->fullSizeX = $this->sizeX + $this->shiftXleft + $this->shiftXright + 1;
     $this->fullSizeY = $this->sizeY + $this->shiftY + $this->legendOffsetY;
     if ($this->drawLegend) {
         $this->fullSizeY += 14 * ($this->num + 1 + ($this->sizeY < 120 ? 0 : count($this->triggers))) + 8;
     }
     // if graph height is big enough, we reserve space for percent line legend
     if ($this->sizeY >= ZBX_GRAPH_LEGEND_HEIGHT) {
         foreach ($this->percentile as $percentile) {
             if ($percentile['percent'] > 0 && $percentile['value']) {
                 $this->fullSizeY += 14;
             }
         }
     }
     if (function_exists('imagecolorexactalpha') && function_exists('imagecreatetruecolor') && @imagecreatetruecolor(1, 1)) {
         $this->im = imagecreatetruecolor($this->fullSizeX, $this->fullSizeY);
     } else {
         $this->im = imagecreate($this->fullSizeX, $this->fullSizeY);
     }
     $this->initColors();
     $this->drawRectangle();
     $this->drawHeader();
     $this->drawWorkPeriod();
     $this->drawTimeGrid();
     $this->drawHorizontalGrid();
     $this->drawXYAxisScale($this->graphtheme['gridbordercolor']);
     $maxX = $this->sizeX;
     // for each metric
     for ($item = 0; $item < $this->num; $item++) {
         $minY = $this->m_minY[$this->items[$item]['axisside']];
         $maxY = $this->m_maxY[$this->items[$item]['axisside']];
         $data =& $this->data[$this->items[$item]['itemid']][$this->items[$item]['calc_type']];
         if (!isset($data)) {
             continue;
         }
         if ($this->type == GRAPH_TYPE_STACKED) {
             $drawtype = $this->items[$item]['drawtype'];
             $max_color = $this->getColor('ValueMax', GRAPH_STACKED_ALFA);
             $avg_color = $this->getColor($this->items[$item]['color'], GRAPH_STACKED_ALFA);
             $min_color = $this->getColor('ValueMin', GRAPH_STACKED_ALFA);
             $minmax_color = $this->getColor('ValueMinMax', GRAPH_STACKED_ALFA);
             $calc_fnc = $this->items[$item]['calc_fnc'];
         } else {
             $drawtype = $this->items[$item]['drawtype'];
             $max_color = $this->getColor('ValueMax', GRAPH_STACKED_ALFA);
             $avg_color = $this->getColor($this->items[$item]['color'], GRAPH_STACKED_ALFA);
             $min_color = $this->getColor('ValueMin', GRAPH_STACKED_ALFA);
             $minmax_color = $this->getColor('ValueMinMax', GRAPH_STACKED_ALFA);
             $calc_fnc = $this->items[$item]['calc_fnc'];
         }
         // for each X
         $draw = true;
         $prevDraw = true;
         for ($i = 1, $j = 0; $i < $maxX; $i++) {
             // new point
             if ($data['count'][$i] == 0 && $i != $maxX - 1) {
                 continue;
             }
             $diff = abs($data['clock'][$i] - $data['clock'][$j]);
             $cell = ($this->to_time - $this->from_time) / $this->sizeX;
             $delay = $this->items[$item]['delay'];
             if ($cell > $delay) {
                 $draw = (bool) ($diff < ZBX_GRAPH_MAX_SKIP_CELL * $cell);
             } else {
                 $draw = (bool) ($diff < ZBX_GRAPH_MAX_SKIP_DELAY * $delay);
             }
             if ($this->items[$item]['type'] == ITEM_TYPE_TRAPPER) {
                 $draw = true;
             }
             if (!$draw && !$prevDraw) {
                 $draw = true;
                 $valueDrawType = GRAPH_ITEM_DRAWTYPE_BOLD_DOT;
             } else {
                 $valueDrawType = $drawtype;
                 $prevDraw = $draw;
             }
             if ($draw) {
                 $this->drawElement($data, $i, $j, 0, $this->sizeX, $minY, $maxY, $valueDrawType, $max_color, $avg_color, $min_color, $minmax_color, $calc_fnc, $this->items[$item]['axisside']);
             }
             $j = $i;
         }
     }
     $this->drawSides();
     if ($this->drawLegend) {
         $this->drawTriggers();
         $this->drawPercentile();
         $this->drawLegend();
     }
     $this->drawLogo();
     $str = sprintf('%0.2f', microtime(true) - $start_time);
     $str = _s('Data from %1$s. Generated in %2$s sec.', $this->dataFrom, $str);
     $strSize = imageTextSize(6, 0, $str);
     imageText($this->im, 6, 0, $this->fullSizeX - $strSize['width'] - 5, $this->fullSizeY - 5, $this->getColor('Gray'), $str);
     unset($this->items, $this->data);
     imageOut($this->im);
 }
Пример #5
0
 private function drawSides()
 {
     if (isset($this->axis_valuetype[GRAPH_YAXIS_SIDE_RIGHT]) && ($this->yaxisright != 0 || $this->skipRightScale != 1)) {
         $sides[] = GRAPH_YAXIS_SIDE_RIGHT;
     }
     if (isset($this->axis_valuetype[GRAPH_YAXIS_SIDE_LEFT]) && ($this->yaxisleft != 0 || $this->skipLeftScale != 1) || !isset($sides)) {
         $sides[] = GRAPH_YAXIS_SIDE_LEFT;
     }
     foreach ($sides as $side) {
         $minY = $this->m_minY[$side];
         $maxY = $this->m_maxY[$side];
         $units = null;
         $unitsLong = null;
         $byteStep = false;
         for ($item = 0; $item < $this->num; $item++) {
             if ($this->items[$item]['axisside'] == $side) {
                 // check if items use B or Bps units
                 if ($this->items[$item]['units'] == 'B' || $this->items[$item]['units'] == 'Bps') {
                     $byteStep = true;
                 }
                 if (is_null($units)) {
                     $units = $this->items[$item]['units'];
                 } elseif ($this->items[$item]['units'] != $units) {
                     $units = '';
                 }
             }
         }
         if (is_null($units) || $units === false) {
             $units = '';
         } else {
             for ($item = 0; $item < $this->num; $item++) {
                 if ($this->items[$item]['axisside'] == $side && !empty($this->items[$item]['unitsLong'])) {
                     $unitsLong = $this->items[$item]['unitsLong'];
                     break;
                 }
             }
         }
         if (!empty($unitsLong)) {
             $dims = imageTextSize(9, 90, $unitsLong);
             $tmpY = $this->sizeY / 2 + $this->shiftY + $dims['height'] / 2;
             if ($tmpY < $dims['height']) {
                 $tmpY = $dims['height'] + 6;
             }
             $tmpX = $side == GRAPH_YAXIS_SIDE_LEFT ? $dims['width'] + 8 : $this->fullSizeX - $dims['width'];
             imageText($this->im, 9, 90, $tmpX, $tmpY, $this->getColor($this->graphtheme['textcolor'], 0), $unitsLong);
         }
         $step = $this->gridStep[$side];
         $hstr_count = $this->gridLinesCount[$side];
         // ignore milliseconds if  -1 <= maxY => 1 or -1 <= minY => 1
         $ignoreMillisec = bccomp($maxY, -1) <= 0 || bccomp($maxY, 1) >= 0 || bccomp($minY, -1) <= 0 || bccomp($minY, 1) >= 0;
         $newPow = false;
         if ($byteStep) {
             $maxYPow = convertToBase1024($maxY, 1024);
             $minYPow = convertToBase1024($minY, 1024);
             $powStep = 1024;
         } else {
             $maxYPow = convertToBase1024($maxY);
             $minYPow = convertToBase1024($minY);
             $powStep = 1000;
         }
         if (abs($maxYPow['pow']) > abs($minYPow['pow']) && $maxYPow['value'] != 0) {
             $newPow = $maxYPow['pow'];
             if (abs(bcdiv($minYPow['value'], bcpow($powStep, $maxYPow['pow']))) > 1000) {
                 $newPow = $minYPow['pow'];
             }
         }
         if (abs($maxYPow['pow']) < abs($minYPow['pow']) && $minYPow['value'] != 0) {
             $newPow = $minYPow['pow'];
             if (abs(bcdiv($maxYPow['value'], bcpow($powStep, $minYPow['pow']))) > 1000) {
                 $newPow = $maxYPow['pow'];
             }
         }
         if ($maxYPow['pow'] == $minYPow['pow']) {
             $newPow = $maxYPow['pow'];
         }
         $maxLength = false;
         // get all values in y-axis if units != 's'
         if ($units != 's') {
             $calcValues = array();
             for ($i = 0; $i <= $hstr_count; $i++) {
                 $hstr_count = $hstr_count == 0 ? 1 : $hstr_count;
                 $val = bcadd(bcmul($i, $step), $minY);
                 if (bccomp(bcadd($val, bcdiv($step, 2)), $maxY) == 1) {
                     continue;
                 }
                 $calcValues[] = convert_units(array('value' => $val, 'convert' => ITEM_CONVERT_NO_UNITS, 'byteStep' => $byteStep, 'pow' => $newPow));
             }
             $calcValues[] = convert_units(array('value' => $maxY, 'convert' => ITEM_CONVERT_NO_UNITS, 'byteStep' => $byteStep, 'pow' => $newPow));
             $maxLength = calcMaxLengthAfterDot($calcValues);
         }
         for ($i = 0; $i <= $hstr_count; $i++) {
             $hstr_count = $hstr_count == 0 ? 1 : $hstr_count;
             $val = bcadd(bcmul($i, $step), $minY);
             if (bccomp(bcadd($val, bcdiv($step, 2)), $maxY) == 1) {
                 continue;
             }
             $str = convert_units(array('value' => $val, 'units' => $units, 'convert' => ITEM_CONVERT_NO_UNITS, 'byteStep' => $byteStep, 'pow' => $newPow, 'ignoreMillisec' => $ignoreMillisec, 'length' => $maxLength));
             if ($side == GRAPH_YAXIS_SIDE_LEFT) {
                 $dims = imageTextSize(8, 0, $str);
                 $posX = $this->shiftXleft - $dims['width'] - 9;
             } else {
                 $posX = $this->sizeX + $this->shiftXleft + 12;
             }
             // marker Y coordinate
             $posY = $this->sizeY + $this->shiftY - $this->gridStepX[$side] * $i + 4;
             imageText($this->im, 8, 0, $posX, $posY, $this->getColor($this->graphtheme['textcolor'], 0), $str);
         }
         $str = convert_units(array('value' => $maxY, 'units' => $units, 'convert' => ITEM_CONVERT_NO_UNITS, 'byteStep' => $byteStep, 'pow' => $newPow, 'ignoreMillisec' => $ignoreMillisec, 'length' => $maxLength));
         if ($side == GRAPH_YAXIS_SIDE_LEFT) {
             $dims = imageTextSize(8, 0, $str);
             $posX = $this->shiftXleft - $dims['width'] - 9;
             $color = $this->getColor(GRAPH_ZERO_LINE_COLOR_LEFT);
         } else {
             $posX = $this->sizeX + $this->shiftXleft + 12;
             $color = $this->getColor(GRAPH_ZERO_LINE_COLOR_RIGHT);
         }
         imageText($this->im, 8, 0, $posX, $this->shiftY + 4, $this->getColor($this->graphtheme['textcolor'], 0), $str);
         if ($this->zero[$side] != $this->sizeY + $this->shiftY && $this->zero[$side] != $this->shiftY) {
             zbx_imageline($this->im, $this->shiftXleft, $this->zero[$side], $this->shiftXleft + $this->sizeX, $this->zero[$side], $color);
         }
     }
 }
Пример #6
0
/**
 * Draws a text on an image. Supports TrueType fonts.
 *
 * @param resource 	$image
 * @param int		$fontsize
 * @param int 		$angle
 * @param int		$x
 * @param int 		$y
 * @param int		$color		a numeric color identifier from imagecolorallocate() or imagecolorallocatealpha()
 * @param string	$string
 */
function imageText($image, $fontsize, $angle, $x, $y, $color, $string)
{
    if (preg_match(ZBX_PREG_DEF_FONT_STRING, $string) && $angle != 0 || ZBX_FONT_NAME == ZBX_GRAPH_FONT_NAME) {
        $ttf = ZBX_FONTPATH . '/' . ZBX_FONT_NAME . '.ttf';
        imagettftext($image, $fontsize, $angle, $x, $y, $color, $ttf, $string);
    } elseif ($angle == 0) {
        $ttf = ZBX_FONTPATH . '/' . ZBX_GRAPH_FONT_NAME . '.ttf';
        imagettftext($image, $fontsize, $angle, $x, $y, $color, $ttf, $string);
    } else {
        $ttf = ZBX_FONTPATH . '/' . ZBX_GRAPH_FONT_NAME . '.ttf';
        $size = imageTextSize($fontsize, 0, $string);
        $imgg = imagecreatetruecolor($size['width'] + 1, $size['height']);
        $transparentColor = imagecolorallocatealpha($imgg, 200, 200, 200, 127);
        imagefill($imgg, 0, 0, $transparentColor);
        imagettftext($imgg, $fontsize, 0, 0, $size['height'], $color, $ttf, $string);
        $imgg = imagerotate($imgg, $angle, $transparentColor);
        imagealphablending($imgg, false);
        imagesavealpha($imgg, true);
        imagecopy($image, $imgg, $x - $size['height'], $y - $size['width'], 0, 0, $size['height'], $size['width'] + 1);
        imagedestroy($imgg);
    }
}
Пример #7
0
function drawMapLabels(&$im, &$map, &$map_info)
{
    global $colors;
    if ($map['label_type'] == MAP_LABEL_TYPE_NOTHING) {
        return;
    }
    $selements = $map['selements'];
    $all_strings = '';
    $label_lines = array();
    $status_lines = array();
    foreach ($selements as $selementid => $selement) {
        if (!isset($label_lines[$selementid])) {
            $label_lines[$selementid] = array();
        }
        if (!isset($status_lines[$selementid])) {
            $status_lines[$selementid] = array();
        }
        $msg = resolveMapLabelMacrosAll($selement);
        $all_strings .= $msg;
        $msgs = explode("\n", $msg);
        foreach ($msgs as $msg) {
            $label_lines[$selementid][] = array('msg' => $msg);
        }
        $el_info = $map_info[$selementid];
        $el_msgs = array('problem', 'unack', 'maintenance', 'unknown', 'ok', 'status');
        foreach ($el_msgs as $key => $caption) {
            if (!isset($el_info['info'][$caption]) || zbx_empty($el_info['info'][$caption]['msg'])) {
                continue;
            }
            $status_lines[$selementid][] = array('msg' => $el_info['info'][$caption]['msg'], 'color' => $el_info['info'][$caption]['color']);
            $all_strings .= $el_info['info'][$caption]['msg'];
        }
    }
    $allLabelsSize = imageTextSize(8, 0, str_replace("\r", '', str_replace("\n", '', $all_strings)));
    $labelFontHeight = $allLabelsSize['height'];
    $labelFontBaseline = $allLabelsSize['baseline'];
    foreach ($selements as $selementid => $selement) {
        if (empty($selement)) {
            continue;
        }
        $el_info = $map_info[$selementid];
        $hl_color = null;
        $st_color = null;
        if (!isset($_REQUEST['noselements']) && $map['highlight'] % 2 == SYSMAP_HIGHLIGH_ON) {
            if ($el_info['icon_type'] == SYSMAP_ELEMENT_ICON_ON) {
                $hl_color = true;
            }
            if ($el_info['icon_type'] == SYSMAP_ELEMENT_ICON_UNKNOWN) {
                $hl_color = true;
            }
            if ($el_info['icon_type'] == SYSMAP_ELEMENT_ICON_MAINTENANCE) {
                $st_color = true;
            }
            if ($el_info['icon_type'] == SYSMAP_ELEMENT_ICON_DISABLED) {
                $st_color = true;
            }
        }
        if (in_array($selement['elementtype'], array(SYSMAP_ELEMENT_TYPE_HOST_GROUP, SYSMAP_ELEMENT_TYPE_MAP)) && !is_null($hl_color)) {
            $st_color = null;
        } else {
            if (!is_null($st_color)) {
                $hl_color = null;
            }
        }
        $label_location = is_null($selement['label_location']) || $selement['label_location'] < 0 ? $map['label_location'] : $selement['label_location'];
        $label = array();
        if ($selement['elementtype'] == SYSMAP_ELEMENT_TYPE_HOST && $map['label_type'] == MAP_LABEL_TYPE_IP) {
            $host = get_host_by_hostid($selement['elementid']);
            $label[] = array('msg' => $host['ip']);
            $label = array_merge($label, $status_lines[$selementid]);
        } else {
            if ($map['label_type'] == MAP_LABEL_TYPE_STATUS) {
                $label = $status_lines[$selementid];
            } else {
                if ($map['label_type'] == MAP_LABEL_TYPE_NAME) {
                    $label[] = array('msg' => $el_info['name']);
                } else {
                    $label = array_merge($label_lines[$selementid], $status_lines[$selementid]);
                }
            }
        }
        if (zbx_empty($label)) {
            continue;
        }
        $w = 0;
        foreach ($label as $str) {
            $dims = imageTextSize(8, 0, $str['msg']);
            $w = max($w, $dims['width']);
        }
        $h = count($label) * $labelFontHeight;
        $x = $selement['x'];
        $y = $selement['y'];
        $img = get_png_by_selement($selement, $el_info);
        $iconX = imagesx($img);
        $iconY = imagesy($img);
        if (!is_null($hl_color)) {
            $icon_hl = 14;
        } else {
            if (!is_null($st_color)) {
                $icon_hl = 6;
            } else {
                $icon_hl = 2;
            }
        }
        switch ($label_location) {
            case MAP_LABEL_LOC_TOP:
                $y_rec = $y - $icon_hl - $h - 6;
                $x_rec = $x + $iconX / 2 - $w / 2;
                break;
            case MAP_LABEL_LOC_LEFT:
                $y_rec = $y - $h / 2 + $iconY / 2;
                $x_rec = $x - $icon_hl - $w;
                break;
            case MAP_LABEL_LOC_RIGHT:
                $y_rec = $y - $h / 2 + $iconY / 2;
                $x_rec = $x + $iconX + $icon_hl;
                break;
            case MAP_LABEL_LOC_BOTTOM:
            default:
                $y_rec = $y + $iconY + $icon_hl;
                $x_rec = $x + $iconX / 2 - $w / 2;
        }
        //		$y_rec += 30;
        //		imagerectangle($im, $x_rec-2-1, $y_rec-3, $x_rec+$w+2+1, $y_rec+($oc*4)+$h+3, $label_color);
        //		imagefilledrectangle($im, $x_rec-2, $y_rec-2, $x_rec+$w+2, $y_rec+($oc*4)+$h-2, $colors['White']);
        $increasey = 12;
        foreach ($label as $line) {
            if (zbx_empty($line['msg'])) {
                continue;
            }
            $str = str_replace("\r", '', $line['msg']);
            $color = isset($line['color']) ? $line['color'] : $colors['Black'];
            $dims = imageTextSize(8, 0, $str);
            //				$dims['height'] = $labelFontHeight;
            //$str .= ' - '.$labelFontHeight.' - '.$dims['height'];
            //$str = $dims['width'].'x'.$dims['height'];
            if ($label_location == MAP_LABEL_LOC_TOP || $label_location == MAP_LABEL_LOC_BOTTOM) {
                $x_label = $x + ceil($iconX / 2) - ceil($dims['width'] / 2);
            } else {
                if ($label_location == MAP_LABEL_LOC_LEFT) {
                    $x_label = $x_rec + $w - $dims['width'];
                } else {
                    $x_label = $x_rec;
                }
            }
            imagefilledrectangle($im, $x_label - 1, $y_rec + $increasey - $labelFontHeight + $labelFontBaseline, $x_label + $dims['width'] + 1, $y_rec + $increasey + $labelFontBaseline, $colors['White']);
            imagetext($im, 8, 0, $x_label, $y_rec + $increasey, $color, $str);
            $increasey += $labelFontHeight + 1;
        }
    }
}
Пример #8
0
$fields = array('text' => array(T_ZBX_STR, O_OPT, P_SYS, null, null), 'font' => array(T_ZBX_INT, O_OPT, null, BETWEEN(1, 5), null), 'color' => array(T_ZBX_STR, O_OPT, null, null, null));
check_fields($fields);
$text = get_request('text', ' ');
$font = get_request('font', 9);
$color = get_request('color', 'black');
switch ($color) {
    case 'white':
        $color = array('red' => 255, 'green' => 255, 'blue' => 255);
        $shadow = array('red' => 105, 'green' => 105, 'blue' => 105);
        break;
    case 'black':
    default:
        $color = array('red' => 0, 'green' => 0, 'blue' => 0);
        $shadow = array('red' => 175, 'green' => 175, 'blue' => 175);
}
$size = imageTextSize($font, $angle, $text);
$im = imagecreatetruecolor($size['width'] + 4, $size['height'] + 4);
$width = imagesx($im);
$height = imagesy($im);
$white = imagecolorallocate($im, $shadow['red'], $shadow['green'], $shadow['blue']);
imagefilledrectangle($im, 0, 0, $width - 1, $height - 1, $white);
$text_color = imagecolorallocate($im, $color['red'], $color['green'], $color['blue']);
imageText($im, $font, 0, 0, $size['height'], $text_color, $text);
$newImage = imagecreatetruecolor($height, $width);
$white = imagecolorallocate($newImage, $shadow['red'], $shadow['green'], $shadow['blue']);
// imagealphablending($newImage, false);
// imagesavealpha($newImage, true);
for ($w = 0; $w < $width; $w++) {
    for ($h = 0; $h < $height; $h++) {
        $ref = imagecolorat($im, $w, $h);
        imagesetpixel($newImage, $h, $width - 1 - $w, $ref);
Пример #9
0
function imageText($image, $fontsize, $angle, $x, $y, $color, $string)
{
    $gdinfo = gd_info();
    if ($gdinfo['FreeType Support'] && function_exists('imagettftext')) {
        if (preg_match(ZBX_PREG_DEF_FONT_STRING, $string) && $angle != 0 || ZBX_FONT_NAME == ZBX_GRAPH_FONT_NAME) {
            $ttf = ZBX_FONTPATH . '/' . ZBX_FONT_NAME . '.ttf';
            imagettftext($image, $fontsize, $angle, $x, $y, $color, $ttf, $string);
        } elseif ($angle == 0) {
            $ttf = ZBX_FONTPATH . '/' . ZBX_GRAPH_FONT_NAME . '.ttf';
            imagettftext($image, $fontsize, $angle, $x, $y, $color, $ttf, $string);
        } else {
            $ttf = ZBX_FONTPATH . '/' . ZBX_GRAPH_FONT_NAME . '.ttf';
            $size = imageTextSize($fontsize, 0, $string);
            $imgg = imagecreatetruecolor($size['width'] + 1, $size['height']);
            $transparentColor = imagecolorallocatealpha($imgg, 200, 200, 200, 127);
            imagefill($imgg, 0, 0, $transparentColor);
            imagettftext($imgg, $fontsize, 0, 0, $size['height'], $color, $ttf, $string);
            $imgg = imagerotate($imgg, $angle, $transparentColor);
            ImageAlphaBlending($imgg, false);
            imageSaveAlpha($imgg, true);
            imagecopy($image, $imgg, $x - $size['height'], $y - $size['width'], 0, 0, $size['height'], $size['width'] + 1);
            imagedestroy($imgg);
        }
    } else {
        show_error_message(_('PHP gd FreeType support missing'));
    }
}
Пример #10
0
 public function draw()
 {
     $start_time = microtime(true);
     set_image_header();
     $this->column = uint_in_array($this->type, array(GRAPH_TYPE_COLUMN, GRAPH_TYPE_COLUMN_STACKED));
     $this->fullSizeX = $this->sizeX;
     $this->fullSizeY = $this->sizeY;
     if ($this->sizeX < 300 || $this->sizeY < 200) {
         $this->showLegend(0);
     }
     $this->calcShifts();
     $this->sizeX -= $this->shiftXleft + $this->shiftXright + $this->shiftlegendright + $this->shiftXCaptionLeft + $this->shiftXCaptionRight;
     $this->sizeY -= $this->shiftY + $this->shiftYLegend + $this->shiftYCaptionBottom + $this->shiftYCaptionTop;
     $this->calcSeriesWidth();
     $this->calcMiniMax();
     $this->correctMiniMax();
     if (function_exists('imagecolorexactalpha') && function_exists('imagecreatetruecolor') && @imagecreatetruecolor(1, 1)) {
         $this->im = imagecreatetruecolor($this->fullSizeX, $this->fullSizeY);
     } else {
         $this->im = imagecreate($this->fullSizeX, $this->fullSizeY);
     }
     $this->initColors();
     $this->drawRectangle();
     $this->drawHeader();
     $this->drawGrid();
     $this->drawSideValues();
     $this->drawLogo();
     $this->drawLegend();
     $count = 0;
     if ($this->column) {
         $start = $this->shiftXleft + $this->shiftXCaptionLeft + floor($this->seriesDistance / 2);
     } else {
         $start = $this->sizeY + $this->shiftY + $this->shiftYCaptionTop - floor($this->seriesDistance / 2);
     }
     foreach ($this->series as $key => $series) {
         foreach ($series as $num => $serie) {
             $axis = $serie['axis'];
             $value = $serie['value'];
             $color = $this->getColor($this->seriesColor[$num], $this->opacity);
             if ($this->column) {
                 imagefilledrectangle($this->im, $start, $this->sizeY + $this->shiftY + $this->shiftYCaptionTop - round($this->sizeY / $this->maxValue[$axis] * $value), $start + $this->columnWidth, $this->sizeY + $this->shiftY + $this->shiftYCaptionTop, $color);
                 imagerectangle($this->im, $start, $this->sizeY + $this->shiftY + $this->shiftYCaptionTop - round($this->sizeY / $this->maxValue[$axis] * $value), $start + $this->columnWidth, $this->sizeY + $this->shiftY + $this->shiftYCaptionTop, $this->getColor('Black No Alpha'));
             } else {
                 imagefilledrectangle($this->im, $this->shiftXleft + $this->shiftXCaptionLeft, $start - $this->columnWidth, $this->shiftXleft + $this->shiftXCaptionLeft + round($this->sizeX / $this->maxValue[$axis] * $value), $start, $color);
                 imagerectangle($this->im, $this->shiftXleft + $this->shiftXCaptionLeft, $start - $this->columnWidth, $this->shiftXleft + $this->shiftXCaptionLeft + round($this->sizeX / $this->maxValue[$axis] * $value), $start, $this->getColor('Black No Alpha'));
             }
             $start = $this->column ? $start + $this->columnWidth : $start - $this->columnWidth;
         }
         $count++;
         if ($this->column) {
             $start = $count * ($this->seriesWidth + $this->seriesDistance) + $this->shiftXleft + $this->shiftXCaptionLeft + floor($this->seriesDistance / 2);
         } else {
             $start = $this->sizeY + $this->shiftY + $this->shiftYCaptionTop - $count * ($this->seriesWidth + $this->seriesDistance) - floor($this->seriesDistance / 2);
         }
     }
     $str = sprintf('%0.2f', microtime(true) - $start_time);
     $str = _s('Generated in %s sec', $str);
     $strSize = imageTextSize(6, 0, $str);
     imageText($this->im, 6, 0, $this->fullSizeX - $strSize['width'] - 5, $this->fullSizeY - 5, $this->getColor('Gray'), $str);
     unset($this->items, $this->data);
     imageOut($this->im);
 }
Пример #11
0
 private function drawRightSide()
 {
     if ($this->yaxisright == 0 || $this->skipRightScale == 1) {
         return;
     }
     $minY = $this->m_minY[GRAPH_YAXIS_SIDE_RIGHT];
     $maxY = $this->m_maxY[GRAPH_YAXIS_SIDE_RIGHT];
     $units = null;
     $unitsLong = null;
     for ($item = 0; $item < $this->num; $item++) {
         if ($this->items[$item]['axisside'] == GRAPH_YAXIS_SIDE_RIGHT) {
             if (is_null($units)) {
                 $units = $this->items[$item]['units'];
             } else {
                 if ($this->items[$item]['units'] != $units) {
                     $units = false;
                 }
             }
         }
     }
     if (is_null($units) || $units === false) {
         $units = '';
     } else {
         for ($item = 0; $item < $this->num; $item++) {
             if ($this->items[$item]['axisside'] == GRAPH_YAXIS_SIDE_RIGHT && !empty($this->items[$item]['unitsLong'])) {
                 $unitsLong = $this->items[$item]['unitsLong'];
                 break;
             }
         }
     }
     if (!empty($unitsLong)) {
         $dims = imageTextSize(9, 90, $unitsLong);
         $tmpY = $this->sizeY / 2 + $this->shiftY + $dims['height'] / 2;
         if ($tmpY < $dims['height']) {
             $tmpY = $dims['height'] + 6;
         }
         imageText($this->im, 9, 90, $this->fullSizeX - $dims['width'], $tmpY, $this->getColor($this->graphtheme['textcolor'], 0), $unitsLong);
     }
     $step = $this->gridStep[GRAPH_YAXIS_SIDE_RIGHT];
     $hstr_count = $this->gridLinesCount[GRAPH_YAXIS_SIDE_RIGHT];
     for ($i = 0; $i <= $hstr_count; $i++) {
         if ($hstr_count == 0) {
             continue;
         }
         //using bc module in case of large numbers
         $val = bcadd(bcmul($i, $step), $minY);
         if (bccomp(bcadd($val, bcdiv($step, 2)), $maxY) == 1) {
             continue;
         }
         $str = convert_units($val, $units, ITEM_CONVERT_NO_UNITS);
         imageText($this->im, 8, 0, $this->sizeX + $this->shiftXleft + 12, $this->sizeY - $this->gridStepX[GRAPH_YAXIS_SIDE_RIGHT] * $i + $this->shiftY + 4, $this->getColor($this->graphtheme['textcolor'], 0), $str);
     }
     $str = convert_units($maxY, $units, ITEM_CONVERT_NO_UNITS);
     imageText($this->im, 8, 0, $this->sizeX + $this->shiftXleft + 12, $this->shiftY + 4, $this->getColor($this->graphtheme['textcolor'], 0), $str);
     if ($this->zero[GRAPH_YAXIS_SIDE_RIGHT] != $this->sizeY + $this->shiftY && $this->zero[GRAPH_YAXIS_SIDE_RIGHT] != $this->shiftY) {
         imageline($this->im, $this->shiftXleft, $this->zero[GRAPH_YAXIS_SIDE_RIGHT], $this->shiftXleft + $this->sizeX, $this->zero[GRAPH_YAXIS_SIDE_RIGHT], $this->getColor(GRAPH_ZERO_LINE_COLOR_RIGHT));
         //*/
     }
 }
Пример #12
0
imagefilledrectangle($im, 0, 0, $width, $height, $colors['White']);
if ($db_image = get_image_by_imageid($backgroundid)) {
    $back = imagecreatefromstring($db_image['image']);
    imagecopy($im, $back, 0, 0, 0, 0, imagesx($back), imagesy($back));
}
unset($db_image);
$x = imagesx($im) / 2 - ImageFontWidth(4) * zbx_strlen($name) / 2;
imagetext($im, 10, 0, $x, 25, $colors['Dark Red'], $name);
$str = zbx_date2str(S_MAPS_DATE_FORMAT, time(NULL));
imagestring($im, 0, imagesx($im) - 120, imagesy($im) - 12, $str, $colors['Gray']);
if (isset($_REQUEST['grid'])) {
    $grid = get_request('grid', 50);
    if (!is_numeric($grid)) {
        $grid = 50;
    }
    $dims = imageTextSize(8, 0, '11');
    for ($x = $grid; $x < $width; $x += $grid) {
        MyDrawLine($im, $x, 0, $x, $height, $colors['Black'], MAP_LINK_DRAWTYPE_DASHED_LINE);
        imageText($im, 8, 0, $x + 3, $dims['height'] + 3, $colors['Black'], $x);
    }
    for ($y = $grid; $y < $height; $y += $grid) {
        MyDrawLine($im, 0, $y, $width, $y, $colors['Black'], MAP_LINK_DRAWTYPE_DASHED_LINE);
        imageText($im, 8, 0, 3, $y + $dims['height'] + 3, $colors['Black'], $y);
    }
    imageText($im, 8, 0, 2, $dims['height'] + 3, $colors['Black'], 'Y X:');
}
// ACTION /////////////////////////////////////////////////////////////////////////////
$json = new CJSON();
if (isset($_REQUEST['selements']) || isset($_REQUEST['noselements'])) {
    $map['selements'] = get_request('selements', '[]');
    $map['selements'] = $json->decode($map['selements'], true);
Пример #13
0
function drawMapLabels(&$im, $map, $mapInfo, $resolveMacros = true)
{
    global $colors;
    if ($map['label_type'] == MAP_LABEL_TYPE_NOTHING && $map['label_format'] == SYSMAP_LABEL_ADVANCED_OFF) {
        return;
    }
    $selements = $map['selements'];
    $allStrings = '';
    $labelLines = array();
    $statusLines = array();
    foreach ($selements as $sid => $selement) {
        if (isset($selement['elementsubtype']) && $selement['elementsubtype'] == SYSMAP_ELEMENT_SUBTYPE_HOST_GROUP_ELEMENTS) {
            unset($selements[$sid]);
        }
    }
    // set label type and custom label text for all selements
    foreach ($selements as $selementId => $selement) {
        $selements[$selementId]['label_type'] = $map['label_type'];
        if ($map['label_format'] == SYSMAP_LABEL_ADVANCED_OFF) {
            continue;
        }
        switch ($selement['elementtype']) {
            case SYSMAP_ELEMENT_TYPE_HOST_GROUP:
                $selements[$selementId]['label_type'] = $map['label_type_hostgroup'];
                if ($map['label_type_hostgroup'] == MAP_LABEL_TYPE_CUSTOM) {
                    $selements[$selementId]['label'] = $map['label_string_hostgroup'];
                }
                break;
            case SYSMAP_ELEMENT_TYPE_HOST:
                $selements[$selementId]['label_type'] = $map['label_type_host'];
                if ($map['label_type_host'] == MAP_LABEL_TYPE_CUSTOM) {
                    $selements[$selementId]['label'] = $map['label_string_host'];
                }
                break;
            case SYSMAP_ELEMENT_TYPE_TRIGGER:
                $selements[$selementId]['label_type'] = $map['label_type_trigger'];
                if ($map['label_type_trigger'] == MAP_LABEL_TYPE_CUSTOM) {
                    $selements[$selementId]['label'] = $map['label_string_trigger'];
                }
                break;
            case SYSMAP_ELEMENT_TYPE_MAP:
                $selements[$selementId]['label_type'] = $map['label_type_map'];
                if ($map['label_type_map'] == MAP_LABEL_TYPE_CUSTOM) {
                    $selements[$selementId]['label'] = $map['label_string_map'];
                }
                break;
            case SYSMAP_ELEMENT_TYPE_IMAGE:
                $selements[$selementId]['label_type'] = $map['label_type_image'];
                if ($map['label_type_image'] == MAP_LABEL_TYPE_CUSTOM) {
                    $selements[$selementId]['label'] = $map['label_string_image'];
                }
                break;
        }
    }
    foreach ($selements as $selementId => $selement) {
        if (!isset($labelLines[$selementId])) {
            $labelLines[$selementId] = array();
        }
        if (!isset($statusLines[$selementId])) {
            $statusLines[$selementId] = array();
        }
        $msg = $resolveMacros ? CMacrosResolverHelper::resolveMapLabelMacrosAll($selement) : $selement['label'];
        $allStrings .= $msg;
        $msgs = explode("\n", $msg);
        foreach ($msgs as $msg) {
            $labelLines[$selementId][] = array('msg' => $msg);
        }
        $elementInfo = $mapInfo[$selementId];
        foreach (array('problem', 'unack', 'maintenance', 'ok', 'status') as $caption) {
            if (!isset($elementInfo['info'][$caption]) || zbx_empty($elementInfo['info'][$caption]['msg'])) {
                continue;
            }
            $statusLines[$selementId][] = array('msg' => $elementInfo['info'][$caption]['msg'], 'color' => $elementInfo['info'][$caption]['color']);
            $allStrings .= $elementInfo['info'][$caption]['msg'];
        }
    }
    $allLabelsSize = imageTextSize(8, 0, str_replace("\r", '', str_replace("\n", '', $allStrings)));
    $labelFontHeight = $allLabelsSize['height'];
    $labelFontBaseline = $allLabelsSize['baseline'];
    $elementsHostIds = array();
    foreach ($selements as $selement) {
        if ($selement['label_type'] != MAP_LABEL_TYPE_IP) {
            continue;
        }
        if ($selement['elementtype'] == SYSMAP_ELEMENT_TYPE_HOST) {
            $elementsHostIds[] = $selement['elementid'];
        }
    }
    if (!empty($elementsHostIds)) {
        $mapHosts = API::Host()->get(array('hostids' => $elementsHostIds, 'output' => array('hostid'), 'selectInterfaces' => API_OUTPUT_EXTEND));
        $mapHosts = zbx_toHash($mapHosts, 'hostid');
    }
    // draw
    foreach ($selements as $selementId => $selement) {
        if (empty($selement) || $selement['label_type'] == MAP_LABEL_TYPE_NOTHING) {
            continue;
        }
        $elementInfo = $mapInfo[$selementId];
        $hl_color = null;
        $st_color = null;
        if (!isset($_REQUEST['noselements']) && $map['highlight'] % 2 == SYSMAP_HIGHLIGHT_ON) {
            if ($elementInfo['icon_type'] == SYSMAP_ELEMENT_ICON_ON) {
                $hl_color = true;
            }
            if ($elementInfo['icon_type'] == SYSMAP_ELEMENT_ICON_MAINTENANCE) {
                $st_color = true;
            }
            if ($elementInfo['icon_type'] == SYSMAP_ELEMENT_ICON_DISABLED) {
                $st_color = true;
            }
        }
        if (in_array($selement['elementtype'], array(SYSMAP_ELEMENT_TYPE_HOST_GROUP, SYSMAP_ELEMENT_TYPE_MAP)) && !is_null($hl_color)) {
            $st_color = null;
        } elseif (!is_null($st_color)) {
            $hl_color = null;
        }
        $labelLocation = is_null($selement['label_location']) || $selement['label_location'] < 0 ? $map['label_location'] : $selement['label_location'];
        $label = array();
        if ($selement['label_type'] == MAP_LABEL_TYPE_IP && $selement['elementtype'] == SYSMAP_ELEMENT_TYPE_HOST) {
            $interface = reset($mapHosts[$selement['elementid']]['interfaces']);
            $label[] = array('msg' => $interface['ip']);
            $label = array_merge($label, $statusLines[$selementId]);
        } elseif ($selement['label_type'] == MAP_LABEL_TYPE_STATUS) {
            $label = $statusLines[$selementId];
        } elseif ($selement['label_type'] == MAP_LABEL_TYPE_NAME) {
            $label[] = array('msg' => $elementInfo['name']);
            $label = array_merge($label, $statusLines[$selementId]);
        } else {
            $label = array_merge($labelLines[$selementId], $statusLines[$selementId]);
        }
        if (empty($label)) {
            continue;
        }
        $w = 0;
        foreach ($label as $str) {
            $dims = imageTextSize(8, 0, $str['msg']);
            $w = max($w, $dims['width']);
        }
        $h = count($label) * $labelFontHeight;
        $x = $selement['x'];
        $y = $selement['y'];
        $image = get_png_by_selement($elementInfo);
        $iconX = imagesx($image);
        $iconY = imagesy($image);
        if (!is_null($hl_color)) {
            $icon_hl = 14;
        } elseif (!is_null($st_color)) {
            $icon_hl = 6;
        } else {
            $icon_hl = 2;
        }
        switch ($labelLocation) {
            case MAP_LABEL_LOC_TOP:
                $y_rec = $y - $icon_hl - $h - 6;
                $x_rec = $x + $iconX / 2 - $w / 2;
                break;
            case MAP_LABEL_LOC_LEFT:
                $y_rec = $y - $h / 2 + $iconY / 2;
                $x_rec = $x - $icon_hl - $w;
                break;
            case MAP_LABEL_LOC_RIGHT:
                $y_rec = $y - $h / 2 + $iconY / 2;
                $x_rec = $x + $iconX + $icon_hl;
                break;
            case MAP_LABEL_LOC_BOTTOM:
            default:
                $y_rec = $y + $iconY + $icon_hl;
                $x_rec = $x + $iconX / 2 - $w / 2;
        }
        $increasey = 12;
        foreach ($label as $line) {
            if (zbx_empty($line['msg'])) {
                continue;
            }
            $str = str_replace("\r", '', $line['msg']);
            $color = isset($line['color']) ? $line['color'] : $colors['Black'];
            $dims = imageTextSize(8, 0, $str);
            if ($labelLocation == MAP_LABEL_LOC_TOP || $labelLocation == MAP_LABEL_LOC_BOTTOM) {
                $x_label = $x + ceil($iconX / 2) - ceil($dims['width'] / 2);
            } elseif ($labelLocation == MAP_LABEL_LOC_LEFT) {
                $x_label = $x_rec + $w - $dims['width'];
            } else {
                $x_label = $x_rec;
            }
            imagefilledrectangle($im, $x_label - 1, $y_rec + $increasey - $labelFontHeight + $labelFontBaseline, $x_label + $dims['width'] + 1, $y_rec + $increasey + $labelFontBaseline, $colors['White']);
            imagetext($im, 8, 0, $x_label, $y_rec + $increasey, $color, $str);
            $increasey += $labelFontHeight + 1;
        }
    }
}
Пример #14
0
 /**
  * Calculates the size of each row and column.
  *
  * @return void
  */
 private function calcRows()
 {
     $rowHeight = 0;
     $colWidth = array();
     foreach ($this->table as $y => $row) {
         foreach ($row as $x => $col) {
             // calculate size from image
             if (isset($col['image'])) {
                 $dims = array('width' => imagesx($col['image']), 'height' => imagesy($col['image']));
             } else {
                 if (!isset($col['fontsize'])) {
                     $col['fontsize'] = $this->fontsize;
                 }
                 $this->table[$y][$x]['fontsize'] = $col['fontsize'];
                 $dims = imageTextSize($col['fontsize'], 0, $col['text']);
             }
             $this->table[$y][$x]['size'] = $dims;
             $rowHeight = $dims['height'] > $rowHeight ? $dims['height'] : $rowHeight;
             if (!isset($colWidth[$x])) {
                 $colWidth[$x] = $dims['width'];
             } elseif ($dims['width'] > $colWidth[$x]) {
                 $colWidth[$x] = $dims['width'];
             }
         }
     }
     if ($rowHeight < $this->rowheight) {
         $rowHeight = $this->rowheight;
     } else {
         $this->rowheight = $rowHeight;
     }
     foreach ($this->table as $y => $row) {
         foreach ($row as $x => $col) {
             $this->table[$y][$x]['height'] = $rowHeight;
             $this->table[$y][$x]['width'] = $colWidth[$x];
         }
     }
 }
function imageText($image, $fontsize, $angle, $x, $y, $color, $string)
{
    $gdinfo = gd_info();
    if ($gdinfo['FreeType Support'] && function_exists('imagettftext')) {
        if (preg_match(ZBX_PREG_DEF_FONT_STRING, $string) && $angle != 0 || ZBX_FONT_NAME == ZBX_GRAPH_FONT_NAME) {
            $ttf = ZBX_FONTPATH . '/' . ZBX_FONT_NAME . '.ttf';
            imagettftext($image, $fontsize, $angle, $x, $y, $color, $ttf, $string);
        } elseif ($angle == 0) {
            $ttf = ZBX_FONTPATH . '/' . ZBX_GRAPH_FONT_NAME . '.ttf';
            imagettftext($image, $fontsize, $angle, $x, $y, $color, $ttf, $string);
        } else {
            $ttf = ZBX_FONTPATH . '/' . ZBX_GRAPH_FONT_NAME . '.ttf';
            $size = imageTextSize($fontsize, 0, $string);
            $imgg = imagecreatetruecolor($size['width'] + 1, $size['height']);
            $transparentColor = imagecolorallocatealpha($imgg, 200, 200, 200, 127);
            imagefill($imgg, 0, 0, $transparentColor);
            imagettftext($imgg, $fontsize, 0, 0, $size['height'], $color, $ttf, $string);
            $imgg = imagerotate($imgg, $angle, $transparentColor);
            ImageAlphaBlending($imgg, false);
            imageSaveAlpha($imgg, true);
            imagecopy($image, $imgg, $x - $size['height'], $y - $size['width'], 0, 0, $size['height'], $size['width'] + 1);
            imagedestroy($imgg);
        }
    } else {
        $dims = imageTextSize($fontsize, $angle, $string);
        switch ($fontsize) {
            case 5:
                $fontsize = 1;
                break;
            case 6:
                $fontsize = 1;
                break;
            case 7:
                $fontsize = 2;
                break;
            case 8:
                $fontsize = 2;
                break;
            case 9:
                $fontsize = 3;
                break;
            case 10:
                $fontsize = 3;
                break;
            case 11:
                $fontsize = 4;
                break;
            case 12:
                $fontsize = 4;
                break;
            case 13:
                $fontsize = 5;
                break;
            case 14:
                $fontsize = 5;
                break;
            default:
                $fontsize = 2;
                break;
        }
        if ($angle) {
            $x -= $dims['width'];
            $y -= 2;
        } else {
            $y -= $dims['height'] - 2;
        }
        if ($angle > 0) {
            return imagestringup($image, $fontsize, $x, $y, $string, $color);
        }
        return imagestring($image, $fontsize, $x, $y, $string, $color);
    }
    return true;
}
Пример #16
-1
function show_messages($good = false, $okmsg = null, $errmsg = null)
{
    global $page, $ZBX_MESSAGES;
    if (!defined('PAGE_HEADER_LOADED')) {
        //		return null;
    }
    if (defined('ZBX_API_REQUEST')) {
        return null;
    }
    if (!isset($page['type'])) {
        $page['type'] = PAGE_TYPE_HTML;
    }
    $imageMessages = [];
    $title = $good ? $okmsg : $errmsg;
    $messages = isset($ZBX_MESSAGES) ? $ZBX_MESSAGES : [];
    $ZBX_MESSAGES = [];
    switch ($page['type']) {
        case PAGE_TYPE_IMAGE:
            if ($title !== null) {
                $imageMessages[] = ['text' => $title, 'color' => !$good ? ['R' => 255, 'G' => 0, 'B' => 0] : ['R' => 34, 'G' => 51, 'B' => 68]];
            }
            foreach ($messages as $message) {
                $imageMessages[] = ['text' => $message['message'], 'color' => $message['type'] == 'error' ? ['R' => 255, 'G' => 55, 'B' => 55] : ['R' => 155, 'G' => 155, 'B' => 55]];
            }
            break;
        case PAGE_TYPE_XML:
            if ($title !== null) {
                echo htmlspecialchars($title) . "\n";
            }
            foreach ($messages as $message) {
                echo '[' . $message['type'] . '] ' . $message['message'] . "\n";
            }
            break;
        case PAGE_TYPE_HTML:
        default:
            if ($title || $messages) {
                makeMessageBox($good, $messages, $title, true, !$good)->show();
            }
            break;
    }
    // draw an image with the messages
    if ($imageMessages) {
        $imageFontSize = 8;
        // calculate the size of the text
        $imageWidth = 0;
        $imageHeight = 0;
        foreach ($imageMessages as &$msg) {
            $size = imageTextSize($imageFontSize, 0, $msg['text']);
            $msg['height'] = $size['height'] - $size['baseline'];
            // calculate the total size of the image
            $imageWidth = max($imageWidth, $size['width']);
            $imageHeight += $size['height'] + 1;
        }
        unset($msg);
        // additional padding
        $imageWidth += 2;
        $imageHeight += 2;
        // create the image
        $canvas = imagecreate($imageWidth, $imageHeight);
        imagefilledrectangle($canvas, 0, 0, $imageWidth, $imageHeight, imagecolorallocate($canvas, 255, 255, 255));
        // draw each message
        $y = 1;
        foreach ($imageMessages as $msg) {
            $y += $msg['height'];
            imageText($canvas, $imageFontSize, 0, 1, $y, imagecolorallocate($canvas, $msg['color']['R'], $msg['color']['G'], $msg['color']['B']), $msg['text']);
        }
        imageOut($canvas);
        imagedestroy($canvas);
    }
}
Пример #17
-1
 protected function drawLegend()
 {
     if (!$this->drawLegend) {
         return;
     }
     $shiftY = $this->shiftY;
     $shiftX = $this->fullSizeX - $this->shiftlegendright - $this->shiftXright;
     $count = 0;
     foreach ($this->series as $key => $serie) {
         foreach ($serie as $num => $value) {
             $caption = $this->seriesLegend[$num];
             $color = $this->getColor($this->seriesColor[$num], 0);
             imagefilledrectangle($this->im, $shiftX - 5, $shiftY + 14 * $count - 5, $shiftX + 5, $shiftY + 5 + 14 * $count, $color);
             imagerectangle($this->im, $shiftX - 5, $shiftY + 14 * $count - 5, $shiftX + 5, $shiftY + 5 + 14 * $count, $this->getColor('Black No Alpha'));
             $dims = imageTextSize(8, 0, $caption);
             imageText($this->im, 8, 0, $shiftX + 10, $shiftY - 5 + 14 * $count + 10, $this->getColor($this->graphtheme['textcolor'], 0), $caption);
             $count++;
         }
         break;
         //!!!!
     }
 }
Пример #18
-1
    $yt = $sizeY * $true[$i - 1] / 100;
    if ($yt > 0) {
        imagefilledrectangle($im, $x1 + $shiftX, $shiftYup, $x1 + $shiftX + 8, $yt + $shiftYup, imagecolorallocate($im, 235, 120, 120));
        // red
    }
    $yf = $sizeY * $false[$i - 1] / 100;
    if ($yf > 0) {
        imagefilledrectangle($im, $x1 + $shiftX, $yt + $shiftYup, $x1 + $shiftX + 8, $sizeY + $shiftYup, imagecolorallocate($im, 120, 235, 120));
        // green
    }
    if ($yt + $yf > 0) {
        imagerectangle($im, $x1 + $shiftX, $shiftYup, $x1 + $shiftX + 8, $sizeY + $shiftYup, $black);
    }
}
for ($i = 0; $i <= $sizeY; $i += $sizeY / 10) {
    imageText($im, 7, 0, $sizeX + 5 + $shiftX, $sizeY - $i - 4 + $shiftYup + 8, $darkred, $i * ($maxY - $minY) / $sizeY + $minY);
}
imagefilledrectangle($im, $shiftX, $sizeY + $shiftYup + 39, $shiftX + 5, $sizeY + $shiftYup + 44, imagecolorallocate($im, 120, 235, 120));
imagerectangle($im, $shiftX, $sizeY + $shiftYup + 39, $shiftX + 5, $sizeY + $shiftYup + 44, $black);
imageText($im, 8, 0, $shiftX + 9, $sizeY + $shiftYup + 45, $black, _('OK') . ' (%)');
imagefilledrectangle($im, $shiftX, $sizeY + $shiftYup + 54, $shiftX + 5, $sizeY + $shiftYup + 59, imagecolorallocate($im, 235, 120, 120));
imagerectangle($im, $shiftX, $sizeY + $shiftYup + 54, $shiftX + 5, $sizeY + $shiftYup + 59, $black);
imageText($im, 8, 0, $shiftX + 9, $sizeY + $shiftYup + 60, $black, _('Problems') . ' (%)');
imagestringup($im, 1, imagesx($im) - 10, imagesy($im) - 50, ZABBIX_HOMEPAGE, $gray);
$str = sprintf('%0.2f', microtime(true) - $startTime);
$str = _s('Generated in %s sec', $str);
$strSize = imageTextSize(6, 0, $str);
imageText($im, 6, 0, imagesx($im) - $strSize['width'] - 5, imagesy($im) - 5, $gray, $str);
imageOut($im);
imagedestroy($im);
require_once dirname(__FILE__) . '/include/page_footer.php';
Пример #19
-1
function show_messages($bool = true, $okmsg = null, $errmsg = null)
{
    global $page, $ZBX_MESSAGES;
    if (!defined('PAGE_HEADER_LOADED')) {
        return null;
    }
    if (defined('ZBX_API_REQUEST')) {
        return null;
    }
    if (!isset($page['type'])) {
        $page['type'] = PAGE_TYPE_HTML;
    }
    $imageMessages = array();
    if (!$bool && !is_null($errmsg)) {
        $msg = _('ERROR') . ': ' . $errmsg;
    } elseif ($bool && !is_null($okmsg)) {
        $msg = $okmsg;
    }
    if (isset($msg)) {
        switch ($page['type']) {
            case PAGE_TYPE_IMAGE:
                // save all of the messages in an array to display them later in an image
                $imageMessages[] = array('text' => $msg, 'color' => !$bool ? array('R' => 255, 'G' => 0, 'B' => 0) : array('R' => 34, 'G' => 51, 'B' => 68));
                break;
            case PAGE_TYPE_XML:
                echo htmlspecialchars($msg) . "\n";
                break;
            case PAGE_TYPE_HTML:
            default:
                $msg_tab = new CTable($msg, $bool ? 'msgok' : 'msgerr');
                $msg_tab->setCellPadding(0);
                $msg_tab->setCellSpacing(0);
                $row = array();
                $msg_col = new CCol(bold($msg), 'msg_main msg');
                $msg_col->setAttribute('id', 'page_msg');
                $row[] = $msg_col;
                if (isset($ZBX_MESSAGES) && !empty($ZBX_MESSAGES)) {
                    $msg_details = new CDiv(_('Details'), 'blacklink');
                    $msg_details->setAttribute('onclick', 'javascript: showHide("msg_messages", IE ? "block" : "table");');
                    $msg_details->setAttribute('title', _('Maximize') . '/' . _('Minimize'));
                    array_unshift($row, new CCol($msg_details, 'clr'));
                }
                $msg_tab->addRow($row);
                $msg_tab->show();
                break;
        }
    }
    if (isset($ZBX_MESSAGES) && !empty($ZBX_MESSAGES)) {
        if ($page['type'] == PAGE_TYPE_IMAGE) {
            foreach ($ZBX_MESSAGES as $msg) {
                // save all of the messages in an array to display them later in an image
                if ($msg['type'] == 'error') {
                    $imageMessages[] = array('text' => $msg['message'], 'color' => array('R' => 255, 'G' => 55, 'B' => 55));
                } else {
                    $imageMessages[] = array('text' => $msg['message'], 'color' => array('R' => 155, 'G' => 155, 'B' => 55));
                }
            }
        } elseif ($page['type'] == PAGE_TYPE_XML) {
            foreach ($ZBX_MESSAGES as $msg) {
                echo '[' . $msg['type'] . '] ' . $msg['message'] . "\n";
            }
        } else {
            $lst_error = new CList(null, 'messages');
            foreach ($ZBX_MESSAGES as $msg) {
                $lst_error->addItem($msg['message'], $msg['type']);
                $bool = $bool && 'error' !== strtolower($msg['type']);
            }
            $msg_show = 6;
            $msg_count = count($ZBX_MESSAGES);
            if ($msg_count > $msg_show) {
                $msg_count = $msg_show * 16;
                $lst_error->setAttribute('style', 'height: ' . $msg_count . 'px;');
            }
            $tab = new CTable(null, $bool ? 'msgok' : 'msgerr');
            $tab->setCellPadding(0);
            $tab->setCellSpacing(0);
            $tab->setAttribute('id', 'msg_messages');
            $tab->setAttribute('style', 'width: 100%;');
            if (isset($msg_tab) && $bool) {
                $tab->setAttribute('style', 'display: none;');
            }
            $tab->addRow(new CCol($lst_error, 'msg'));
            $tab->show();
        }
        $ZBX_MESSAGES = null;
    }
    // draw an image with the messages
    if ($page['type'] == PAGE_TYPE_IMAGE && count($imageMessages) > 0) {
        $imageFontSize = 8;
        // calculate the size of the text
        $imageWidth = 0;
        $imageHeight = 0;
        foreach ($imageMessages as &$msg) {
            $size = imageTextSize($imageFontSize, 0, $msg['text']);
            $msg['height'] = $size['height'] - $size['baseline'];
            // calculate the total size of the image
            $imageWidth = max($imageWidth, $size['width']);
            $imageHeight += $size['height'] + 1;
        }
        unset($msg);
        // additional padding
        $imageWidth += 2;
        $imageHeight += 2;
        // create the image
        $canvas = imagecreate($imageWidth, $imageHeight);
        imagefilledrectangle($canvas, 0, 0, $imageWidth, $imageHeight, imagecolorallocate($canvas, 255, 255, 255));
        // draw each message
        $y = 1;
        foreach ($imageMessages as $msg) {
            $y += $msg['height'];
            imageText($canvas, $imageFontSize, 0, 1, $y, imagecolorallocate($canvas, $msg['color']['R'], $msg['color']['G'], $msg['color']['B']), $msg['text']);
        }
        imageOut($canvas);
        imagedestroy($canvas);
    }
}
 public function drawHeader()
 {
     if (!isset($this->header)) {
         $str = $this->items[0]['hostname'] . ': ' . $this->items[0]['name'];
     } else {
         $str = $this->header;
     }
     $str .= $this->period2str($this->period);
     // calculate largest font size that can fit graph header
     // TODO: font size must be dynamic in other parts of the graph as well, like legend, timeline, etc
     for ($fontsize = 11; $fontsize > 7; $fontsize--) {
         $dims = imageTextSize($fontsize, 0, $str);
         $x = $this->fullSizeX / 2 - $dims['width'] / 2;
         // most important information must be displayed, period can be out of the graph
         if ($x < 2) {
             $x = 2;
         }
         if ($dims['width'] <= $this->fullSizeX) {
             break;
         }
     }
     imageText($this->im, $fontsize, 0, $x, 24, $this->getColor($this->graphtheme['textcolor'], 0), $str);
 }
Пример #21
-1
 protected function drawLegend()
 {
     $shiftY = $this->shiftY + $this->shiftYLegend;
     $max_host_len = 0;
     $max_desc_len = 0;
     for ($i = 0; $i < $this->num; $i++) {
         if (zbx_strlen($this->items[$i]['host']) > $max_host_len) {
             $max_host_len = zbx_strlen($this->items[$i]['host']);
         }
         if (zbx_strlen($this->items[$i]['description']) > $max_desc_len) {
             $max_desc_len = zbx_strlen($this->items[$i]['description']);
         }
     }
     for ($i = 0; $i < $this->num; $i++) {
         $color = $this->getColor($this->items[$i]['color'], 0);
         $data =& $this->data[$this->items[$i]['itemid']][$this->items[$i]['calc_type']];
         switch ($this->items[$i]['calc_fnc']) {
             case CALC_FNC_MIN:
                 $fnc_name = 'min';
                 $datavalue = $data->min;
                 break;
             case CALC_FNC_MAX:
                 $fnc_name = 'max';
                 $datavalue = $data->max;
                 break;
             case CALC_FNC_LST:
                 $fnc_name = 'last';
                 $datavalue = $data->lst;
                 break;
             case CALC_FNC_AVG:
             default:
                 $fnc_name = 'avg';
                 $datavalue = $data->avg;
         }
         $proc = $datavalue * 100 / $this->sum;
         //			convert_units($datavalue,$this->items[$i]["units"]),
         if (isset($data) && isset($datavalue)) {
             $strvalue = sprintf(S_VALUE . ': %s (' . (round($proc) != $proc ? '%0.2f' : '%s') . '%%)', convert_units($datavalue, $this->items[$i]['units']), $proc);
             $str = sprintf('%s: %s [%s] ', str_pad($this->items[$i]['host'], $max_host_len, ' '), str_pad($this->items[$i]['description'], $max_desc_len, ' '), $fnc_name);
         } else {
             $strvalue = sprintf(S_VALUE . ': ' . S_NO_DATA_SMALL);
             $str = sprintf('%s: %s [ ' . S_NO_DATA_SMALL . ' ]', str_pad($this->items[$i]['host'], $max_host_len, ' '), str_pad($this->items[$i]['description'], $max_desc_len, ' '));
         }
         imagefilledrectangle($this->im, $this->shiftXleft, $this->sizeY + $shiftY + 14 * $i - 5, $this->shiftXleft + 10, $this->sizeY + $shiftY + 5 + 14 * $i, $color);
         imagerectangle($this->im, $this->shiftXleft, $this->sizeY + $shiftY + 14 * $i - 5, $this->shiftXleft + 10, $this->sizeY + $shiftY + 5 + 14 * $i, $this->getColor('Black No Alpha'));
         $dims = imageTextSize(8, 0, $str);
         imageText($this->im, 8, 0, $this->shiftXleft + 15, $this->sizeY + $shiftY + 14 * $i + 5, $this->getColor($this->graphtheme['textcolor'], 0), $str);
         $shiftX = $this->fullSizeX - $this->shiftlegendright - $this->shiftXright + 25;
         //		SDI($shiftX.','.$this->sizeX);
         imagefilledrectangle($this->im, $shiftX - 10, $this->shiftY + 10 + 14 * $i, $shiftX, $this->shiftY + 10 + 10 + 14 * $i, $color);
         imagerectangle($this->im, $shiftX - 10, $this->shiftY + 10 + 14 * $i, $shiftX, $this->shiftY + 10 + 10 + 14 * $i, $this->GetColor('Black No Alpha'));
         imagetext($this->im, 8, 0, $shiftX + 5, $this->shiftY + 10 + 14 * $i + 10, $this->getColor($this->graphtheme['textcolor'], 0), $strvalue);
     }
     if ($this->sizeY < 120) {
         return;
     }
 }