function Graf($arrayX, $arrayY, $ImageHandle, $MinX, $MaxX, $MinY, $MaxY, $Color = 'FF0000', $dashed = "N", $thikness = 2, $antialiase = true) { global $xA, $yA, $xPixelLength, $yPixelLength; if (sizeof($arrayX) != sizeof($arrayY)) { return; } $arr_Color = ReColor($Color); $color = ImageColorAllocate($ImageHandle, $arr_Color[0], $arr_Color[1], $arr_Color[2]); $xGrafLength = $MaxX - $MinX; $yGrafLength = $MaxY - $MinY; if ($antialiase) { $bgcolor = imagecolorallocate($ImageHandle, 255, 255, 255); $fgcolors = imagecolorsforindex($ImageHandle, $color); $bgcolors = imagecolorsforindex($ImageHandle, $bgcolor); for ($i = 0; $i < 100; $i++) { imagecolorallocate($ImageHandle, ($fgcolors['red'] + $i * $bgcolors['red']) / ($i + 1), ($fgcolors['green'] + $i * $bgcolors['green']) / ($i + 1), ($fgcolors['blue'] + $i * $bgcolors['blue']) / ($i + 1)); } } $x1 = $y1 = $x2 = $y2 = 0; for ($i = 0, $n = sizeof($arrayX) - 1; $i < $n; $i++) { if ($xGrafLength > 0) { $x1 = $xA + ($arrayX[$i] - $MinX) * $xPixelLength / $xGrafLength; $x2 = $xA + ($arrayX[$i + 1] - $MinX) * $xPixelLength / $xGrafLength; } if ($yGrafLength > 0) { $y1 = $yA - ($arrayY[$i] - $MinY) * $yPixelLength / $yGrafLength; $y2 = $yA - ($arrayY[$i + 1] - $MinY) * $yPixelLength / $yGrafLength; } $x1 = ceil($x1); $y1 = ceil($y1); $x2 = ceil($x2); $y2 = ceil($y2); if ($antialiase) { /** @noinspection PhpUndefinedVariableInspection */ _a_draw_line($ImageHandle, $x1, $y1, $x2, $y2, $fgcolors, $dashed, 10, 4); if ($thikness > 1) { if ($y1 < $y2) { _a_draw_line($ImageHandle, $x1 - 0.4, $y1 + 0.4, $x2 - 0.4, $y2 + 0.4, $fgcolors, $dashed, 10, 4); _a_draw_line($ImageHandle, $x1 + 0.4, $y1 - 0.4, $x2 + 0.4, $y2 - 0.4, $fgcolors, $dashed, 10, 4); } else { _a_draw_line($ImageHandle, $x1 + 0.4, $y1 + 0.4, $x2 + 0.4, $y2 + 0.4, $fgcolors, $dashed, 10, 4); _a_draw_line($ImageHandle, $x1 - 0.4, $y1 - 0.4, $x2 - 0.4, $y2 - 0.4, $fgcolors, $dashed, 10, 4); } } } elseif ($dashed == "Y") { $style = array($color, $color, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT); ImageSetStyle($ImageHandle, $style); ImageLine($ImageHandle, $x1, $y1, $x2, $y2, IMG_COLOR_STYLED); } else { ImageLine($ImageHandle, $x1, $y1, $x2, $y2, $color); } } }
function DrawDashedLine($x1, $y1, $x2, $y2, $dash_length, $dash_space, $color) { if ($dash_length) { $dashes = array_fill(0, $dash_length, $color); } else { $dashes = array(); } if ($dash_space) { $spaces = array_fill(0, $dash_space, IMG_COLOR_TRANSPARENT); } else { $spaces = array(); } $style = array_merge($dashes, $spaces); ImageSetStyle($this->img, $style); ImageLine($this->img, $x1, $y1, $x2, $y2, IMG_COLOR_STYLED); }
<?php require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/tools.php"; include $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/advertising/colors.php"; require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/img.php"; if (function_exists("FormDecode")) { FormDecode(); } UnQuoteAll(); // создаем изображение $ImageHendle = CreateImageHandle(45, 2); $dec = ReColor($color); $color = ImageColorAllocate($ImageHendle, $dec[0], $dec[1], $dec[2]); if ($dash == "Y") { $style = array($color, $color, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT); //$white = ImageColorAllocate($ImageHendle,255,255,255); //$style = array ($color,$color,$white,$white,$white); ImageSetStyle($ImageHendle, $style); ImageLine($ImageHendle, 3, 0, 40, 0, IMG_COLOR_STYLED); ImageLine($ImageHendle, 1, 1, 40, 1, IMG_COLOR_STYLED); } else { ImageLine($ImageHendle, 3, 0, 40, 0, $color); ImageLine($ImageHendle, 3, 1, 40, 1, $color); } /****************************************************** ќтображаем изображение *******************************************************/ ShowImageHeader($ImageHendle);
/** * Get the GD applicable linestyle * * @param mixed $lineStyle The line style to return, false if the one * explicitly set * @return mixed A GD compatible linestyle * @access private */ function _getLineStyle($lineStyle = false) { if ($this->_gd2) { ImageSetThickness($this->_canvas, $this->_thickness); } if ($lineStyle == 'transparent') { return false; } elseif ($lineStyle === false) { if (is_array($this->_lineStyle)) { $colors = array(); foreach ($this->_lineStyle as $color) { if ($color === 'transparent') { $color = false; } $colors[] = $this->_color($color); } ImageSetStyle($this->_canvas, $colors); return IMG_COLOR_STYLED; } else { return $this->_color($this->_lineStyle); } } else { return $this->_color($lineStyle); } }
private static function MDashedLine($image, $x0, $y0, $x1, $y1, $fg, $bg) { $st = array($fg, $fg, $fg, $fg, $bg, $bg, $bg, $bg); ImageSetStyle($image, $st); ImageLine($image, $x0, $y0, $x1, $y1, IMG_COLOR_STYLED); }
function _DashedLine($x0, $y0, $x1, $y1, $fg, $bg) { $st = array($fg, $fg, $fg, $fg, $bg, $bg, $bg, $bg); ImageSetStyle($this->graph, $st); ImageLine($this->graph, $x0, $y0, $x1, $y1, IMG_COLOR_STYLED); }
/** * Create Timeline Image * * @param $date * @param $draw if FALSE return coordinates only, for imagemap * @param $translate for translate * @param $img_type [normal | small] * @return image */ public function createTimelineImage($date, $draw = true, $translate = null, $img_type = 'normal') { $this->GetDataTimeline($date); if (empty($this->atime)) { // Nothing data to graph return; } $this->calculateImageData($img_type); if (!$draw) { $img_map = array(); } $ttf_font_error = 0; // созд-е пустого холста // Create a new true color image : // resource imagecreatetruecolor ( int width, int height ) $img = ImageCreateTrueColor($this->img_width, $this->img_height); if (!$img) { // Handle the error $this->view->result = null; $this->getResponse()->setHeader('Content-Type', 'text/html; charset=utf-8'); throw new Zend_Exception('Internal ERROR: ImageCreateTrueColor'); return; } // цвета $white = ImageColorAllocate($img, 255, 255, 255); $black = ImageColorAllocate($img, 0, 0, 0); $blue = ImageColorAllocate($img, 0x49, 0x74, 0xbc0); // массив цветов для полос $acolor = array(ImageColorAllocate($img, 0xea, 0xea, 0x33), ImageColorAllocate($img, 0xff, 0xba, 0xba), ImageColorAllocate($img, 0xd0, 0xae, 0xff), ImageColorAllocate($img, 0x9d, 0xed, 0x0), ImageColorAllocate($img, 0xdc, 0xdc, 0xdc)); $acolor_count = count($acolor); // кол-во цветов для рисования полос $bg_color = $white; $text_color = $black; // создание фона для рисования // Draw a filled rectangle : bool imagefilledrectangle ( resource image, int x1, int y1, int x2, int y2, int color ) if ($draw) { ImageFilledRectangle($img, 0, 0, $this->img_width, $this->img_height, $bg_color); } // контур фона // Draw a rectangle : bool imagerectangle ( resource image, int x1, int y1, int x2, int y2, int color ) if ($draw) { ImageRectangle($img, 0, 0, $this->img_width - 1, $this->img_height - 1, $blue); } // --------------------------------- вычерчивание координатной сетки --------------------------------------- // ось X // Draw a line : // bool imageline ( resource image, int x1, int y1, int x2, int y2, int color ) // $y0, $x0 - начало координат $y0 = $y2 = $this->img_height - $this->margin_bottom - $this->margin_top + $this->bar_space; $x0 = $this->margin_left; if ($draw) { ImageLine($img, $x0, $y0, $this->img_width - $this->margin_right, $y2, $blue); } // ось X // вертикальные линии - часы // пунктирная линия $style_dash = array_merge(array_fill(0, 1, $blue), array_fill(0, 3, IMG_COLOR_TRANSPARENT)); if ($draw) { ImageSetStyle($img, $style_dash); } $hour1 = ceil(($this->img_width - $x0 - $this->margin_right) / 24); // шаг засечек или 1 час в пикселах $y2 = 0; for ($i = 0; $i <= 23; $i++) { $x1 = $x0 + $i * $hour1; ImageLine($img, $x1, $y0, $x1, $y2, IMG_COLOR_STYLED); } if ($img_type == 'normal') { // подписи к оси X $y1 = $this->img_height - $this->margin_bottom - $this->margin_top + $this->bar_space + $this->font_size; for ($i = 0; $i <= 23; $i++) { // Draw a string horizontally : // bool imagestring ( resource image, int font, int x, int y, string sring, int color ) // Can be 1, 2, 3, 4, 5 for built-in fonts (where higher numbers corresponding to larger fonts) // для учета кол-ва символов в цифрах часов if ($i < 10) { $div2 = 10; } else { $div2 = 5; } $x1 = $x0 - $div2 + $i * $hour1; if ($draw) { ImageString($img, 4, $x1, $y1, sprintf("% 2d", $i), $blue); } } // X axis title / название оси X if (empty($this->font_name)) { // use system fixed font / ось подписываем встроенным шрифтом if ($draw) { ImageString($img, $this->fixfont, floor($this->img_width / 2), $this->img_height - floor(($this->img_height - $y0) / 2), "Hours", $blue); } // do not to translate (перевод не нужен) } else { if ($draw) { @($ares = ImageTtfText($img, $this->font_size, 0, floor($this->img_width / 2), $this->img_height - floor(($this->img_height - $y0) / 3), $blue, $this->font_name, $translate->_("Hours"))); if (empty($ares)) { $ttf_font_error = 1; // TTF font not loaded/found if ($draw) { ImageString($img, 4, 5, 5, "Font " . $this->font_name . " not loaded/found.", $black); } // do not to translate (перевод не нужен) } } } } //---------------- draw graph (рисуем график) -------------------------------------------- $yt = $this->margin_top; $c = 0; for ($i = 0; $i <= $this->bar_count - 1; $i++) { $str = '(' . $this->atime[$i]['jobid'] . ') ' . $this->atime[$i]['name']; // для заданий не уложившихся в сутки, рисуем знаки с определенной стороны switch ($this->atime[$i]['flag']) { case -1: $str = '<--' . $str; // задание началось ранее break; case 1: $str = $str . '-->'; // задание закончилось позднее break; case 2: $str = '<--' . $str . '-->'; // задание началось ранее и закончилось позднее (очень длинное задание) break; } // Draw a filled rectangle: // bool imagefilledrectangle ( resource image, int x1, int y1, int x2, int y2, int color ) // полосы $yr1 = $yt - ceil($this->font_size / 2) - ceil($this->bar_height / 2); $yr2 = $yr1 + $this->bar_height; $xr1 = $x0 + floor($hour1 * $this->atime[$i]['h1']); $xr2 = $x0 + floor($hour1 * $this->atime[$i]['h2']); // если слишком маленькая полоса if ($xr2 - $xr1 < 3) { $xr2 = $xr1 + 3; } // цвет if ($c > $acolor_count - 1) { $c = 0; } // draw restangle if ($draw) { ImageFilledRectangle($img, $xr1, $yr1, $xr2, $yr2, $acolor[$c++]); } // Write text to the image using TrueType fonts : // array imagettftext ( resource image, float size, float angle, int x, int y, int color, string fontfile, string text ) // x - The coordinates given by x and y will define the basepoint of the first character // (roughly the lower-left corner of the character). // This is different from the imagestring(), where x and y define the upper-left corner of the first character. // For example, "top left" is 0, 0. // size - The font size. Depending on your version of GD, this should be specified as the pixel size (GD1) or point size (GD2) // **************** text ***************** // array imagettfbbox ( float size, float angle, string fontfile, string text ) // где расположить текст // расчет координат текста // левая координата X = $abox[0], правая X = $abox[2] if (!$ttf_font_error && !empty($this->font_name)) { // TTF font loaded OK $abox = ImageTtfBbox($this->font_size, 0, $this->font_name, $str); $xt = $xr1 + $this->margin_text_left; if ($xt + $abox[2] > $this->img_width) { $xt = $xr2 - $abox[2] - $this->margin_text_left; if (!$draw) { $xt > $xr2 ? $x2 = $xt : ($x2 = $xr2); } // coordinates for imagemap } else { if (!$draw) { $xt + $abox[2] > $xr2 ? $x2 = $xt + $abox[2] : ($x2 = $xr2); } // coordinates for imagemap } // draw text if ($draw) { ImageTtfText($img, $this->font_size, 0, $xt, $yt, $text_color, $this->font_name, $str); } } else { // fix font $lenfix = strlen($str) * imagefontwidth($this->fixfont); if ($xr1 + $lenfix > $this->img_width) { $xt = $xr2 - $lenfix - $this->margin_text_left; if (!$draw) { $xt > $xr2 ? $x2 = $xt : ($x2 = $xr2); } // coordinates for imagemap } else { $xt = $xr1; if (!$draw) { $xt + $lenfix > $xr2 ? $x2 = $xt + $lenfix : ($x2 = $xr2); } // coordinates for imagemap } // draw text if ($draw) { ImageString($img, $this->fixfont, $xt, $yr1, $str, $text_color); } } // save coordinates if (!$draw) { $xt < $xr1 ? $x1 = $xt : ($x1 = $xr1); $img_map[$i]['jobid'] = $this->atime[$i]['jobid']; $img_map[$i]['name'] = $this->atime[$i]['name']; $img_map[$i]['short_desc'] = $this->atime[$i]['short_desc']; $img_map[$i]['x1'] = $x1; $img_map[$i]['y1'] = $yr1; $img_map[$i]['x2'] = $x2; $img_map[$i]['y2'] = $yr2; } $yt = $yt + $this->bar_height + $this->bar_space; } if ($draw) { return $img; } else { return $img_map; } }
function DashedLine($image, $x1, $y1, $x2, $y2, $color) { // Style for dashed lines // $style = array($color, $color, $color, $color, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT); $style = array($color, $color, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT); ImageSetStyle($image, $style); ImageLine($image, $x1, $y1, $x2, $y2, IMG_COLOR_STYLED); }
<?php // make a two-pixel thick black and white dashed line $style = array($black, $black, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT); ImageSetStyle($image, $style);
function create_image2() { $GBC = new GBsql(); $GBC->GB_getSQLsetting(); $GBSQL = "SELECT * from locations "; $result = $GBC->_GBUser->query($GBSQL); $locs = $result->fetchAll(); @(list($level, $gold, $cash, $FarmSizeX, $FarmSizeY) = explode(';', fBGetDataStore('playerinfo'))); if ($FarmSizeX == '' || $FarmSizeY == '') { $GB_place_items = "No"; return; } else { $GB_place_items = "OK"; } $maxX = $FarmSizeX * 4; $maxX = $maxX + 3; $maxY = $FarmSizeY * 4; $maxY = $maxY + 3; $im = @imagecreate($maxX, $maxY) or AddLog2("Cannot Initialize new GD image stream"); $background_color = imagecolorallocate($im, 255, 255, 255); // yellow $red = imagecolorallocate($im, 255, 0, 0); // red $green = imagecolorallocate($im, 0, 255, 0); $blue = imagecolorallocate($im, 0, 0, 255); // blue $white = imagecolorallocate($im, 255, 255, 255); $yellow = imagecolorallocate($im, 255, 255, 0); $black = imagecolorallocate($im, 0, 0, 0); $purple = ImageColorAllocate($im, 153, 51, 255); //purple $pink = ImageColorAllocate($im, 255, 0, 128); //pink $grey = ImageColorAllocate($im, 192, 192, 192); //grey $brown = ImageColorAllocate($im, 51, 0, 0); $loc = "Animal"; $style = array($white, $white, $white, $blue, $blue, $blue); ImageSetStyle($im, $style); $X1 = $GBC->GB_Setting[$loc . 'X1'] * 4; $Y1 = $maxY - $GBC->GB_Setting[$loc . 'Y1'] * 4; $X2 = $GBC->GB_Setting[$loc . 'X2'] * 4; $Y2 = $maxY - $GBC->GB_Setting[$loc . 'Y2'] * 4; imagefilledrectangle($im, $X1, $Y1, $X2, $Y2, IMG_COLOR_STYLED); $loc = "Tree"; $style = array($white, $white, $white, $yellow, $yellow, $yellow); ImageSetStyle($im, $style); $X1 = $GBC->GB_Setting[$loc . 'X1'] * 4; $Y1 = $maxY - $GBC->GB_Setting[$loc . 'Y1'] * 4; $X2 = $GBC->GB_Setting[$loc . 'X2'] * 4; $Y2 = $maxY - $GBC->GB_Setting[$loc . 'Y2'] * 4; imagefilledrectangle($im, $X1, $Y1, $X2, $Y2, IMG_COLOR_STYLED); $loc = "Decoration"; $style = array($white, $white, $white, $black, $black, $black); ImageSetStyle($im, $style); $X1 = $GBC->GB_Setting[$loc . 'X1'] * 4; $Y1 = $maxY - $GBC->GB_Setting[$loc . 'Y1'] * 4; $X2 = $GBC->GB_Setting[$loc . 'X2'] * 4; $Y2 = $maxY - $GBC->GB_Setting[$loc . 'Y2'] * 4; imagefilledrectangle($im, $X1, $Y1, $X2, $Y2, IMG_COLOR_STYLED); foreach ($locs as $loc) { $GB_fill = $red; if (strpos($loc['_what'], 'E') !== false) { $GB_fill = $green; } if (strpos($loc['_what'], 'Decoration') !== false) { $GB_fill = $black; } if (strpos($loc['_what'], 'Animal') !== false) { $GB_fill = $purple; } if (strpos($loc['_what'], 'Building') !== false) { $GB_fill = $pink; } if (strpos($loc['_what'], 'Plot') !== false) { $GB_fill = $brown; } $Map_PXI = $loc['_X'] * 4; $Map_PYI = $loc['_Y'] * 4; $Map_PYI = $maxY - $Map_PYI; imagefilledrectangle($im, $Map_PXI, $Map_PYI, $Map_PXI + 1, $Map_PYI + 1, $GB_fill); } $GB_map_image = $_SESSION['userId'] . "_FarmMap3.png"; imagepng($im, $GB_map_image); imagedestroy($im); }
function MyDrawLine($image, $x1, $y1, $x2, $y2, $color, $drawtype) { if ($drawtype == MAP_LINK_DRAWTYPE_BOLD_LINE) { ImageLine($image, $x1, $y1, $x2, $y2, $color); if ($x1 - $x2 < $y1 - $y2) { $x1++; $x2++; } else { $y1++; $y2++; } ImageLine($image, $x1, $y1, $x2, $y2, $color); } else { if ($drawtype == MAP_LINK_DRAWTYPE_DASHED_LINE) { if (function_exists("imagesetstyle")) { /* Use ImageSetStyle+ImageLIne instead of bugged ImageDashedLine */ $style = array($color, $color, $color, $color, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT); ImageSetStyle($image, $style); ImageLine($image, $x1, $y1, $x2, $y2, IMG_COLOR_STYLED); } else { ImageDashedLine($image, $x1, $y1, $x2, $y2, $color); } } else { if ($drawtype == MAP_LINK_DRAWTYPE_DOT && function_exists("imagesetstyle")) { $style = array($color, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT); ImageSetStyle($image, $style); ImageLine($image, $x1, $y1, $x2, $y2, IMG_COLOR_STYLED); } else { ImageLine($image, $x1, $y1, $x2, $y2, $color); } } } }
/** * Zeichnen einer gestrichelten Linie * * @param object $image * @param int $x0 * @param int $y0 * @param int $x1 * @param int $y1 * @param object $fg * @param object $bg * @since 0.0.1 * @version 0.0.1 * @access private * @return void * @author Alexander Mieland * @copyright 2000-2004 by APP - Another PHP Program */ function _APCMS_DashedLine($image, $x0, $y0, $x1, $y1, $fg, $bg) { $st = array($fg, $fg, $fg, $fg, $bg, $bg, $bg, $bg); ImageSetStyle($image, $st); ImageLine($image, $x0, $y0, $x1, $y1, IMG_COLOR_STYLED); }
/** * draw y axe with lines and numbers * * @param null * @returns nothing */ function drawYAxe() { // draw lines $top = $this->posYStart; $step = round(($this->posYEnd - $this->posYStart) / $this->yTicks, 2); for ($i = 0; $i <= $this->yTicks; $i++) { $style = array($this->colorStyle, $this->colorStyle, $this->colorStyle, $this->colorStyle, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT); ImageSetStyle($this->img, $style); ImageLine($this->img, $this->posXStart - 5, $top, $this->fullYaxe ? $this->posXEnd : $this->posXStart + 5, $top, $this->colorLines); $top += $step; } // draw numbers $xAxeValue = $this->maxData; $top = $this->posYStart; for ($i = 0; $i <= $this->yTicks; $i++) { ImageString($this->img, 2, $this->posXStart - 12 - strlen($xAxeValue) * 4, $top - 6, $xAxeValue, $this->colorText); $xAxeValue -= $this->maxData / $this->yTicks; if ($xAxeValue < 0.01) { $xAxeValue = 0; } $top += $step; } }