Esempio n. 1
0
 public function getGDImageOfMemoryLine(Watcher $Watcher, $width, $height, $y_scale = 1, $memory_size_scale = 1048576)
 {
     $points = $Watcher->getPointsArray();
     if (empty($points) || empty($y_scale) || empty($memory_size_scale)) {
         return false;
     }
     $max_y = $height;
     $max_x = $width;
     $img = imagecreatetruecolor($max_x, $max_y);
     $point_color = imagecolorallocate($img, 0, 0, 255);
     $line_color = imagecolorallocate($img, 0, 255, 0);
     $string_color = imagecolorallocate($img, 0, 0, 0);
     $white = imagecolorallocate($img, 255, 255, 255);
     imagefill($img, 10, 10, $white);
     $x = 0;
     $y = 0;
     $x_step = intval($max_x / 100);
     foreach ($points as $point) {
         $value = round($point[$Watcher::point_memory] / $memory_size_scale, 2);
         $new_x = $x + $x_step;
         $new_y = $value * $y_scale;
         imageline($img, $x + 1, $max_y - $y, $new_x, $max_y - $new_y, $line_color);
         $x = $new_x;
         $y = $new_y;
         imagesetpixel($img, $x, $max_y - $y, $point_color);
         imagestringup($img, 1, $x, $max_y - $y - 5, $point[$Watcher::point_name], $string_color);
         imagestringup($img, 1, $x, $max_y - $y + 30, $value, $string_color);
     }
     return $img;
 }