<?php
$fp = fopen ("ping.txt", "r");
$values = array();
$count = 0;
while (!feof($fp))
{
$line = fgets($fp, 1024);
$input = explode("\ ", $line);
$packet = explode("=", $input[7]);
$packet = $packet[1];
array_push ($values, $packet);
if ($count == 0)
array_pop($values);
$count++;
}
fclose($fp);
$myImage = imagecreate(200, 100);
$myImage = $myImage;
$black = ImageColorAllocate($myImage, 0, 0, 0);
$white = ImageColorAllocate($myImage, 255, 255, 255);
$red = ImageColorAllocate($myImage, 255, 0, 0);
$green = ImageColorAllocate($myImage, 0, 255, 0);
ImageFill($myImage, 0, 0, $white);
ImageRectangle($myImage, 0, 0, 399, 99, $black);
$max=max($values);
$fac=$max/100;
$x=0; $y=0;
foreach ($values as $value)
{
$x_old = $x;
$x += round(400/count($values));
$y = abs($height-($value/$fac));
$y_old = abs($height-($value_old/$fac));
ImageLine($myImage, $x_old, $y_old, $x, $y, $red);
$value_old = $value;
}
ob_start();
imagepng($myImage);
//imageline($myImage, 15, 35, 120, 60, $myBlack);
printf('<img src="data:image/png;base64,%s"/>',
base64_encode(ob_get_clean()));
imagedestroy($myImage);
?>