function nodes_list() { global $db; global $geocalc; global $srtm; global $vars; $this->aCounter = 0; $a_node = get('a_node'); $this->template['a_node'] = $a_node; if ($this->template['a_node'] != '') { $a_node_data = $db->get('id, name, latitude, longitude, elevation', 'nodes', "id = '" . $this->template['a_node'] . "'", '', 'name'); $a_node_data = $a_node_data[0]; $this->template['a_node_output'] = $a_node_data['name'] . ' (#' . $a_node_data['id'] . ')'; } $this->result = "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"table-list\">\n <tr>\n <td width=\"100%\" class=\"table-list-title\">LOS from " . $this->template['a_node_output'] . "</td>\n <td width=\"200\"></td> </tr>\n <tr>\n <td width=\"100%\" colspan=\"2\">\n <table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\">\n <tr>\n <td class=\"table-list-top-cell\">\n Node name\n </td>\n <td class=\"table-list-top-cell\">\n Lat\n </td><td class=\"table-list-top-cell\">\n Long\n </td>" . "<td class=\"table-list-top-cell\">\n Elevation\n </td>" . "<td class=\"table-list-top-cell\">\n Distance\n </td>" . "<td class=\"table-list-top-cell\" colspan=\"2\">\n LOS\n </td>\n </tr>"; $a_node = $db->get('latitude, longitude, elevation', 'nodes', "id = '" . $_GET["a_node"] . "'"); $SQL_select = "SELECT distinct(a.id), a.*, (1000 * acos(\n cos( radians(" . $a_node[0]['latitude'] . ") )\n * cos( radians( latitude ) )\n * cos( radians( longitude )\n - radians(" . $a_node[0]['longitude'] . ") )\n + sin( radians(" . $a_node[0]['latitude'] . ") )\n * sin( radians( latitude ) )\n )\n ) AS distance\n "; $SQL = " FROM nodes a LEFT JOIN links b ON a.id = b.node_id and b.type in ('ap','p2p'" . (get('showall') == '' ? "" : ",'client'") . ") and b.status='active' \n WHERE a.id != " . $_GET["a_node"] . " AND not b.node_id is null " . sprintf("and a.latitude between %.2f and %.2f ", min($vars['map']['bounds']['min_latitude'], $vars['map']['bounds']['max_latitude']), max($vars['map']['bounds']['min_latitude'], $vars['map']['bounds']['max_latitude'])) . sprintf("and a.longitude between %.2f and %.2f ", min($vars['map']['bounds']['min_longitude'], $vars['map']['bounds']['max_longitude']), max($vars['map']['bounds']['min_longitude'], $vars['map']['bounds']['max_longitude'])); //echo $SQL_select.$SQL; $limitRows = isset($vars['constructor']['max_rows']) ? $vars['constructor']['max_rows'] : 20; $r = mysql_query("SELECT COUNT( DISTINCT (a.id) ) AS number " . $SQL); //echo "SELECT COUNT( DISTINCT (a.id) ) AS number ".$SQL; while ($ROW = mysql_fetch_array($r)) { $nodesNum = $ROW['number']; } $sqldo = $SQL_select . $SQL . " order by distance asc\n limit " . (isset($_REQUEST['pg']) ? $_REQUEST['pg'] * $limitRows - $limitRows . ",{$limitRows}" : $limitRows); //echo $sqldo; $RES = mysql_query($sqldo); $a_node = $db->get('latitude, longitude, elevation', 'nodes', "id = '" . $_GET["a_node"] . "'"); $width = 570; $height = 250; while ($ROW = mysql_fetch_array($RES)) { $this->image = imagecreate($width, $height); $b_node = $ROW[0]; $this->template['b_node'] = $b_node; if ($this->template['b_node'] != '') { $b_node_data = $db->get('id, name, latitude, longitude, elevation', 'nodes', "id = '" . $this->template['b_node'] . "'"); $b_node_data = $b_node_data[0]; $this->template['b_node_output'] = $b_node_data['name'] . ' (#' . $b_node_data['id'] . ')'; } $b_node = $db->get('latitude, longitude, elevation', 'nodes', "id = '" . $ROW[0] . "'"); $antenna_a = $a_node[0]["elevation"]; $antenna_b = $b_node[0]["elevation"]; $point_a = new coordinate($a_node[0]['latitude'], $a_node[0]['longitude']); $point_b = new coordinate($b_node[0]['latitude'], $b_node[0]['longitude']); $distance = $geocalc->GCDistance($point_a->lat, $point_a->lon, $point_b->lat, $point_b->lon) * 1000; $ground_pad = $height * (1 / 20); $sky_pad = $height * (1 / 20); $left_pad = 0; $right_pad = 0; $width = $width - $left_pad - $right_pad; $color_sky = ImageColorAllocate($this->image, 99, 200, 248); $color_ground = ImageColorAllocate($this->image, 177, 125, 86); $color_antenna = ImageColorAllocate($this->image, 0, 0, 0); $color_sea = ImageColorAllocate($this->image, 0, 0, 200); $black = ImageColorAllocate($this->image, 0, 0, 0); $color_link_on = ImageColorAllocate($this->image, 57, 187, 77); //THIS IS THE PASS COLOUR $color_link_off = ImageColorAllocate($this->image, 211, 97, 97); //THIS IS THE FAIL COLOUR $step_lat = ($point_b->lat - $point_a->lat) / ($width - 1); $step_log = ($point_b->lon - $point_a->lon) / ($width - 1); for ($i = 0; $i < $width; $i++) { $elevations[$i] = $srtm->get_elevation($point_a->lat + $step_lat * $i, $point_a->lon + $step_log * $i, FALSE); if ($point_a->lat == '' || $point_a->lon == '' || $point_b->lat == '' || $point_b->lon == '' || $elevations[$i] === FALSE) { imagestring($this->image, 5, 10, 10, "Data error!", $black); return $this->image; } if ($elevations[$i] < -32000) { $elevations[$i] = $elevations[$i - 1]; } } $max_el = max($elevations) + max($antenna_a, $antenna_b); $min_el = min($elevations); $step_elevation = ($max_el - $min_el) / ($height - $ground_pad - $sky_pad); $antenna_a_se = $antenna_a / $step_elevation; $antenna_b_se = $antenna_b / $step_elevation; for ($i = 0; $i < $width; $i++) { //GROUND $pixels_el = ($elevations[$i] - $min_el) / $step_elevation; $y1 = $height - 1 - $ground_pad - $pixels_el; $y2 = $height - 1; imagelinethick($this->image, $left_pad + $i, $y1, $left_pad + $i, $y2, $color_ground); //SEA if ($elevations[$i] < 0) { $pixels_el = (0 - $min_el) / $step_elevation; $y2 = $y1; $y1 = $height - 1 - $ground_pad - $pixels_el; imagelinethick($this->image, $left_pad + $i, $y1, $left_pad + $i, $y2, $color_sea); } //ANTENNA A if ($i == 0) { $ant_a = $y1 - $antenna_a_se; } //ANTENNA B if ($i == $width - 2) { $ant_b = $y1 - $antenna_b_se; } } // End for $color_link = $color_link_on; $start = $color_link; $pf = "<div style='color:green;font-weight:bold'>PASS</div>"; for ($i = 0; $i < $width; $i++) { if (imagecolorat($this->image, $left_pad + $i, $ant_a + $i * ($ant_b - $ant_a) / ($width - 1)) == $color_ground) { $color_link = $color_link_off; if ($start != $color_link) { $pf = "<div style='color:red;font-weight:bold'>FAIL</div>"; } break; } } //echo $start." = ".$color_link."<br>"; $this->aDistance[$this->aCounter] = number_format($distance / 1000, 2); $this->aResult[$this->aCounter] = $pf; $this->aNodeName[$this->aCounter] = $this->template["b_node_output"]; $this->aLat[$this->aCounter] = $point_b->lat; $this->aLong[$this->aCounter] = $point_b->lon; $this->aElev[$this->aCounter] = $antenna_b; $this->aID[$this->aCounter] = $this->template['a_node']; $this->bID[$this->aCounter] = $this->template['b_node']; $this->aCounter++; imagedestroy($this->image); } foreach ($this->aDistance as $key => $val) { $this->result .= "<tr class=\"table-list-list1\">\n <td class=\"table-list-cell\">\n <a href=\"\" onclick=\"javascript: t = window.open('?page=nodes&subpage=plot_link&a_node=" . $this->aID[$key] . "&b_node=" . $this->bID[$key] . "', 'popup_plot_link', 'width=600,height=420,toolbar=0,resizable=1,scrollbars=1'); t.focus(); return false;\">" . $this->aNodeName[$key] . "</a>\n </td><td class=\"table-list-cell\">\n " . $this->aLat[$key] . "\n </td><td class=\"table-list-cell\">\n " . $this->aLong[$key] . "\n </td><td class=\"table-list-cell\">\n " . $this->aElev[$key] . "\n </td><td class=\"table-list-cell\">\n " . $this->aDistance[$key] . " km\n </td><td class=\"table-list-cell\">" . $this->aResult[$key] . "</td><td class=\"table-list-cell\">\n <img src=\"" . make_ref(get_path(), array("page" => "nodes", "subpage" => "plot", "a_node" => $this->aID[$key], "b_node" => $this->bID[$key], "width" => 400, "height" => 150)) . "\"/>\n </td>\n </tr>"; } $this->result .= "</table></td></tr>\n <tr><td><br />\n <div style='text-align:center;font-weight:bold;'>Page "; $pgs = $nodesNum / $limitRows; $pg = !isset($_REQUEST['pg']) || $_REQUEST['pg'] < 1 ? "1" : $_REQUEST['pg']; for ($x = 1; $x <= $pgs; $x++) { $this->result .= $x == $pg ? "{$x} " : "<a href='" . make_ref(get_path(), array("page" => "nodes", "subpage" => "list", "a_node" => $this->aID[$key], "pg" => $x)) . "'>{$x} </a>"; } $this->result .= "</div><br /><br /></td><td></td></tr></table>"; }
/** * Generate a random string, and create a CAPTCHA image out of it */ function create_image() { // generate pronouncable pass $pass = genPassword(5, 6); $font = './captcha.ttf'; $maxsize = 50; $sizeVar = 25; $rotate = 20; $bgcol = 50; // + 50 $bgtextcol = 80; // + 50 $textcol = 205; // + 50 // remember the pass $_SESSION["captcha"] = $pass; // calculate dimentions required for pass $box = @imageTTFBbox($maxsize, 0, $font, $pass); $minwidth = abs($box[4] - $box[0]); $minheight = abs($box[5] - $box[1]); // allow spacing for rotating letters $width = $minwidth + 100; $height = $minheight + rand(5, 15); // give some air for the letters to breathe // create initial image $image = ImageCreatetruecolor($width, $height); if (function_exists('imageantialias')) { imageantialias($image, true); } // define background color - never the same, close to black $clr_black = ImageColorAllocate($image, rand($bgcol, $bgcol + 30), rand($bgcol, $bgcol + 30), rand($bgcol, $bgcol + 30)); imagefill($image, 0, 0, $clr_black); // calculate starting positions for letters $x = rand(10, 25); //($width / 2) - ($minwidth / 2); $xinit = $x; $y = $minheight - abs($box[1]) + ($height - $minheight) / 2; // fill the background with big letters, colored a bit lightly, to vary the bg. $bgx = $x / 2; $size = rand($maxsize - 10, $maxsize); for ($i = 0; $i < strlen($pass); $i++) { // modify color a bit $clr_white = ImageColorAllocate($image, rand($bgtextcol, $bgtextcol + 50), rand($bgtextcol, $bgtextcol + 50), rand($bgtextcol, $bgtextcol + 50)); $angle = rand(0 - $rotate, $rotate); $letter = substr($pass, $i, 1); imagettftext($image, $size * 2, $angle, $bgx, $y, $clr_white, $font, $letter); list($x1, $a, $a, $a, $x2) = @imageTTFBbox($size, $angle, $font, $letter); $bgx += abs($x2 - $x1); } // for each letter, decide a color, decide a rotation, put it on the image, // and figure out width to place next letter correctly for ($i = 0; $i < strlen($pass); $i++) { // modify color a bit $clr_white = ImageColorAllocate($image, rand($textcol, $textcol + 50), rand($textcol, $textcol + 50), rand($textcol, $textcol + 50)); $angle = rand(0 - $rotate, $rotate); $letter = substr($pass, $i, 1); $size = rand($maxsize - $sizeVar, $maxsize); $tempbox = @imageTTFBbox($size, $angle, $font, $letter); $y = abs($tempbox[5] - $tempbox[1]) + ($height - abs($tempbox[5] - $tempbox[1])) / 2; imagettftext($image, $size, $angle, $x, $y, $clr_white, $font, $letter); $x += abs($tempbox[4] - $tempbox[0]); } // figure out final width (same space at the end as there was at the beginning) $width = $xinit + $x; // throw in some lines $clr_white = ImageColorAllocate($image, rand(160, 200), rand(160, 200), rand(160, 200)); imagelinethick($image, rand(0, 10), rand(0, $height / 2), rand($width - 10, $width), rand($height / 2, $height), $clr_white, rand(1, 2)); $clr_white = ImageColorAllocate($image, rand(160, 200), rand(160, 200), rand(160, 200)); imagelinethick($image, rand($width / 2 - 10, $width / 2), rand($height / 2, $height), rand($width / 2 + 10, $width), rand(0, $height / 2), $clr_white, rand(1, 2)); // generate final image by cropping initial image to the proper width, // which we didn't know till now. $finalimage = ImageCreatetruecolor($width, $height); if (function_exists('imageantialias')) { imageantialias($finalimage, true); } imagecopy($finalimage, $image, 0, 0, 0, 0, $width, $height); // clear some memory imagedestroy($image); // dump image imagepng($finalimage); // clear some more memory imagedestroy($finalimage); }
if (($delta_x == 0) and ($delta_y == 0)){ continue; }; $pixel_x = round($last_lat_x + ($cur_lat - $last_lat)/$GradPerPixel,3); $pixel_y = round($last_long_y + ($cur_long - $last_long)*cos(deg2rad($cur_lat))/$GradPerPixel,3); $delta_x=sprintf("%01.0f",($pixel_x - $last_lat_x)); $delta_y=sprintf("%01.0f",($pixel_y - $last_long_y)); if (($delta_x == 0) and ($delta_y == 0)){ continue; }; imagelinethick($image, $last_lat_x, $last_long_y, $pixel_x, $pixel_y, $white, "2"); // imageline($image, $last_lat_x, $last_long_y, $pixel_x, $pixel_y, $white); $last_lat=$cur_lat; $last_long=$cur_long; $last_lat_x=$pixel_x; $last_long_y=$pixel_y; } fclose($file); $image = imagerotate($image, 90, 0); imagejpeg($image, $trackfile, 100); imagedestroy($image);
function plotlink($width, $height, $point_a, $point_b, $antenna_a = 0, $antenna_b = 0) { global $geocalc, $srtm; $distance = $geocalc->GCDistance($point_a->lat, $point_a->lon, $point_b->lat, $point_b->lon) * 1000; $image = imagecreate($width, $height); $ground_pad = $height * (1 / 20); $sky_pad = $height * (1 / 20); $left_pad = 0; $right_pad = 0; $width = $width - $left_pad - $right_pad; $color_sky = ImageColorAllocate($image, 99, 200, 248); $color_ground = ImageColorAllocate($image, 177, 125, 86); $color_antenna = ImageColorAllocate($image, 0, 0, 0); $color_sea = ImageColorAllocate($image, 0, 0, 200); $black = ImageColorAllocate($image, 0, 0, 0); $color_link_on = ImageColorAllocate($image, 57, 187, 77); $color_link_off = ImageColorAllocate($image, 211, 97, 97); $step_lat = ($point_b->lat - $point_a->lat) / ($width - 1); $step_log = ($point_b->lon - $point_a->lon) / ($width - 1); for ($i = 0; $i < $width; $i++) { $elevations[$i] = $srtm->get_elevation($point_a->lat + $step_lat * $i, $point_a->lon + $step_log * $i, FALSE); if ($point_a->lat == '' || $point_a->lon == '' || $point_b->lat == '' || $point_b->lon == '' || $elevations[$i] === FALSE) { imagestring($image, 5, 10, 10, "Data error!", $black); return $image; } if ($elevations[$i] < -32000) { $elevations[$i] = $elevations[$i - 1]; } } $max_el = max($elevations) + max($antenna_a, $antenna_b); $min_el = min($elevations); $step_elevation = ($max_el - $min_el) / ($height - $ground_pad - $sky_pad); //$step_elevation = $distance / $width; //step_elevation for real distances plotting $antenna_a_se = $antenna_a / $step_elevation; $antenna_b_se = $antenna_b / $step_elevation; for ($i = 0; $i < $width; $i++) { //GROUND $pixels_el = ($elevations[$i] - $min_el) / $step_elevation; $y1 = $height - 1 - $ground_pad - $pixels_el; $y2 = $height - 1; imagelinethick($image, $left_pad + $i, $y1, $left_pad + $i, $y2, $color_ground); //SEA if ($elevations[$i] < 0) { $pixels_el = (0 - $min_el) / $step_elevation; $y2 = $y1; $y1 = $height - 1 - $ground_pad - $pixels_el; imagelinethick($image, $left_pad + $i, $y1, $left_pad + $i, $y2, $color_sea); } //ANTENNA A if ($i == 0) { $ant_a = $y1 - $antenna_a_se; imagelinethick($image, $left_pad + $i, $y1, $left_pad + $i, $ant_a, $color_antenna, 2); } //ANTENNA B if ($i == $width - 2) { $ant_b = $y1 - $antenna_b_se; imagelinethick($image, $left_pad + $i, $y1, $left_pad + $i, $ant_b, $color_antenna, 2); } } $color_link = $color_link_on; for ($i = 0; $i < $width; $i++) { if (imagecolorat($image, $left_pad + $i, $ant_a + $i * ($ant_b - $ant_a) / ($width - 1)) == $color_ground) { $color_link = $color_link_off; break; } } imagelinethick($image, $left_pad + 0, $ant_a, $left_pad + $width - 1, $ant_b, $color_link, 1); //FRESNEL ZONE $freq = (int) $_GET['frequency']; if ($freq <= 0) { $freq = 2450; } $ant_a_r = round($ant_a); $ant_b_r = round($ant_b); $p_correction = 0; $p06_correction = 0; for ($i = 1; $i < $width - 1; $i++) { $a_total = $elevations[0] + $antenna_a; $b_total = $elevations[$width - 1] + $antenna_b; $d1 = $i / $width * $distance; if ((int) ($i / 2) % 2 == 0) { // dashed line $fresnel = 17.32 * sqrt($d1 * ($distance - $d1) / ($freq * $distance)); $correction = sqrt(pow($b_total - $a_total, 2) * pow($fresnel, 2) / (pow($distance, 2) + pow($b_total - $a_total, 2))); $fresnel = sqrt(pow($fresnel, 2) - pow($correction, 2)); $correction = round($correction / $step_elevation) * ($b_total > $a_total ? -1 : 1); $fresnel = $fresnel / $step_elevation; imagesetpixel($image, $left_pad + $i - $correction, round($ant_a_r + $i * ($ant_b_r - $ant_a_r) / ($width - 1) + $fresnel), $color_link); imagesetpixel($image, $left_pad + $i + $correction, round($ant_a_r + $i * ($ant_b_r - $ant_a_r) / ($width - 1) - $fresnel), $color_link); if ($p_correction < $correction) { imagesetpixel($image, $left_pad + $i + $correction - 1, round($ant_a_r + $i * ($ant_b_r - $ant_a_r) / ($width - 1) - $fresnel), $color_link); } $p_correction = $correction; } $fresnel06 = 0.6 * 17.32 * sqrt($d1 * ($distance - $d1) / ($freq * $distance)); $correction = sqrt(pow($b_total - $a_total, 2) * pow($fresnel06, 2) / (pow($distance, 2) + pow($b_total - $a_total, 2))); $fresnel06 = sqrt(pow($fresnel06, 2) - pow($correction, 2)); $correction = round($correction / $step_elevation) * ($b_total > $a_total ? -1 : 1); $fresnel06 = $fresnel06 / $step_elevation; //echo $fresnel06."-".$correction."-".$ant_a."-".($ant_a + $i * ($ant_b - $ant_a) / ($width - 1))."<br />"; imagesetpixel($image, $left_pad + $i - $correction, round($ant_a_r + $i * ($ant_b_r - $ant_a_r) / ($width - 1) + $fresnel06), $color_link); imagesetpixel($image, $left_pad + $i + $correction, round($ant_a_r + $i * ($ant_b_r - $ant_a_r) / ($width - 1) - $fresnel06), $color_link); if ($p06_correction < $correction) { imagesetpixel($image, $left_pad + $i + $correction - 1, round($ant_a_r + $i * ($ant_b_r - $ant_a_r) / ($width - 1) - $fresnel06), $color_link); } //imagesetpixel($image, $left_pad + $i, round($ant_a) + round($i * (round($ant_b) - round($ant_a)) / ($width-1)), $color_ground); $p06_correction = $correction; } return $image; }
function getFullGraph($grdata, $height, $width, $imageurl, $winStreak, $loseStreak) { require './../variables.php'; // BackGround color if (!empty($_GET["bgc"])) { $bgcolor["r"] = hexdec(substr($_GET["bgc"], 0, 2)); $bgcolor["g"] = hexdec(substr($_GET["bgc"], 2, 2)); $bgcolor["b"] = hexdec(substr($_GET["bgc"], 4, 2)); } else { $bgcolor = array("r" => 243, "g" => 243, "b" => 255); //DEFAULT BG Color } // Line color $fcolor = array("r" => 0, "g" => 0, "b" => 0); // DEFAULT Line Color // Image Height if (!empty($height)) { $img_height = $height; } else { $img_height = 30; // DEFAULT } if ($grdata == null) { $img_width = $width; if ($imageurl == null) { $img = imagecreate($img_width, $img_height); //CREATE image $img_bgc = imagecolorallocate($img, $bgcolor["r"], $bgcolor["g"], $bgcolor["b"]); imagefilledrectangle($img, 0, 0, $img_width, $img_height, $img_bgc); // Draw background color over image } else { $img = imagecreatefrompng($imageurl); } $font_line1 = 3; $offset_left = $img_width - 70; $offset_line1 = $img_height - 20; $string_line1 = "no data"; $fontcolor_normal = imagecolorallocate($img, 0, 0, 0); imagestring($img, $font_line1, $offset_left, $offset_line1, $string_line1, $fontcolor_normal); return $img; } if (!empty($width)) { $img_width = $width; } else { $img_width = round($img_height) * sizeof($grdata); // DEFAULT } $itemVal = 0; $data_max = 0; $data_min = 0; $stepData = array(); foreach ($grdata as $item) { $itemVal += $item[0]; $stepData[] = $itemVal; $dbgStr .= "<br> item:" . $item[0] . " val:" . $itemVal . "<br>"; if ($itemVal > $data_max) { $data_max = $itemVal; } else { if ($itemVal < $data_min) { $data_min = $itemVal; } } } if ($data_max == $data_min) { // MAX and MIN is same => CENTER THE LINE $data_max = $data_max + 1; $data_min = $data_min - 1; } $data_const = $img_height / ($data_max - $data_min); //ReCalculating CONST (used to center graph (y-array) $dbgStr .= "data_max: " . $data_max . " data_min: " . $data_min . " data_const: " . $data_const; if (sizeof($grdata) > 1) { $data_step = $img_width / (sizeof($grdata) - 1); // STEP for drawing (x-array) } else { $data_step = $img_width; } if (!empty($stepData)) { foreach ($stepData as $value) { // ReCalculate data array to fit the image $res = round(($value - $data_min) * $data_const, 3); $res = $img_height - $res; if ($res < 0) { $res++; } if ($res >= $img_height) { $res--; } $data_gr[] = $res; } } if ($imageurl == null) { $img = imagecreate($img_width, $img_height); //CREATE image $img_bgc = imagecolorallocate($img, $bgcolor["r"], $bgcolor["g"], $bgcolor["b"]); $img_fc = imagecolorallocate($img, $fcolor["r"], $fcolor["g"], $fcolor["b"]); imagefilledrectangle($img, 0, 0, $img_width, $img_height, $img_bgc); // Draw background color over image } else { $img = imagecreatefrompng($imageurl); } $x = 0; // draw helper $y = $data_gr[0]; // DATA helper (first value) $dbgStr .= "<br>grdata: " . print_r($grdata, true) . "<br>"; $dbgStr .= "<br>data_gr: " . print_r($data_gr, true) . "<br>"; for ($loop = 1; $loop < sizeof($grdata); $loop++) { // LineDrawing LOOP $x_start = $x; $y_start = $y; $dbgStr .= "------------------------------ grdata: <b>" . $grdata[$loop] . "</b> - data_gr: <b>" . $data_gr[$loop] . "</b><Br>"; $dbgStr .= "x_start: <b>" . $x_start . "</b> - y_start: <b>" . $y_start . "</b><br>"; $x = $x + $data_step; $y = $data_gr[$loop]; $colorHex = $grdata[$loop - 1][1]; $color = imagecolorallocate($img, hexdec(substr($colorHex, 0, 2)), hexdec(substr($colorHex, 2, 2)), hexdec(substr($colorHex, 4, 2))); $dbgStr .= "x: <b>" . $x . "</b> - y: <b>" . $y . "</b><p>"; if (strcmp($colorHex, $graph_red) == 0 || strcmp($colorHex, $graph_green) == 0) { $thickness = 1.5; } else { $thickness = 1; } imagelinethick($img, $x_start, $y_start, $x, $y, $color, $thickness); $streak = $grdata[$loop - 1][2]; if ($streak > 0) { if (strcmp($colorHex, $graph_red) == 0) { $offx = 0; $offy = -13; } else { $offx = -10; $offy = -13; } $font = 1; $fontcolor = $color; $offset_left = $x + $offx; $offset_top = $y + $offy; if ($offset_top < 15) { $offset_top = $offset_top + 20; } imagestring($img, $font, $offset_left, $offset_top, $streak, $fontcolor); } } return $img; }
$period = 24 * 3600; //création du fond de la carte $im = ImageCreate(2 * $larg + $decall + 60, 2 * $larg + $decalv + 20) or die("Erreur lors de la création de l'image"); $fond = imagecolorallocatealpha($im, 255, 255, 255, 127); ImageFill($im, 0, 0, $fond); //couleurs de base $bleu = ImageColorAllocate($im, 17, 17, 150); $bleu_c = ImageColorAllocate($im, 100, 117, 200); for ($i = 1; $i < $nb_pt; $i++) { // imageline($im, $coord[2*$i-2]*$coeff+$decall+$larg, -$coord[2*$i-1]*$coeff+$decalv+$larg, $coord[2*$i]*$coeff+$decall+$larg, -$coord[2*$i+1]*$coeff+$decalv+$larg, $bleu_c ); $dx = $coord[2 * $i] - $coord[2 * $i - 2]; $dy = $coord[2 * $i + 1] - $coord[2 * $i - 1]; //Détermination de la forme du trajet if (abs($dx) < abs($dy)) { $x_inter = $coord[2 * $i]; $y_inter = $dy < 0 ? $coord[2 * $i - 1] - abs($dx) : $coord[2 * $i - 1] + abs($dx); } else { $x_inter = $dx > 0 ? $coord[2 * $i - 2] + abs($dy) : $coord[2 * $i - 2] - abs($dy); $y_inter = $coord[2 * $i + 1]; } //Affichage des lignes imagelinethick($im, $coord[2 * $i - 2] * $coeff + $decall + $larg, -$coord[2 * $i - 1] * $coeff + $decalv + $larg, $x_inter * $coeff + $decall + $larg, -$y_inter * $coeff + $decalv + $larg, $bleu_c, 2); imagelinethick($im, $x_inter * $coeff + $decall + $larg, -$y_inter * $coeff + $decalv + $larg, $coord[2 * $i] * $coeff + $decall + $larg, -$coord[2 * $i + 1] * $coeff + $decalv + $larg, $bleu_c, 2); //affichage des points ImageFilledEllipse($im, $coord[2 * $i] * $coeff + $decall + $larg, -$coord[2 * $i + 1] * $coeff + $decalv + $larg, 6, 6, $bleu_c); } ImageFilledEllipse($im, $coord[0] * $coeff + $decall + $larg, -$coord[1] * $coeff + $decalv + $larg, 6, 6, $bleu_c); ImageColorTransparent($im, $blanc); //export image header("Content-type: image/png"); ImagePng($im);
// $y_hr = $r_hr * sin(deg2rad(($hours-3) * (360/12))) + 224; // imageline($img, 224, 224, $x_sec, $y_sec, $red); // imagesetthickness($img, 3); // imageline($img, 224, 224, $x_min, $y_min, $black); // imagesetthickness($img, 5); // imageline($img, 224, 224, $x_hr, $y_hr, $black); // header("Content-type: image/png"); // imagepng($img); // imagedestroy($img); 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); } imagelinethick($image, $x1, $y1, $x2, $y2, $color, $thick = 1);