Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2016
416
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.35 KB | None | 0 0
  1. <?php
  2.  
  3.     //read file in ?file= parameter
  4.  
  5.     if(isset($_GET["im"])){
  6.         header("Content-type: image/png");
  7.     }
  8.  
  9.     $val = $_GET["val"]-1; //Byte 1 - 19
  10.     $annotation = $_GET["alt"]; //comment
  11.     $fh = fopen($_GET["file"],"r");
  12.     $data = fread($fh,filesize($_GET["file"]));
  13.     $lines = explode("\n",$data);
  14.     $numlines = count($lines); // wie viel zeilen die data.log hat.
  15.  
  16.     //graph
  17.     $imheight = 300;
  18.  
  19.     //$im = imagecreatefrompng("empty.png"); // wird nur für transparent gebraucht, unnötig
  20.  
  21.     $im = imagecreate(($numlines*3)+32,$imheight);
  22.  
  23.     //colors
  24.  
  25.     $black = imagecolorallocate($im,0,0,0);
  26.     $red = imagecolorallocate($im,255,0,0);
  27.     $gray = imagecolorallocate($im,65,55,55);
  28.     $white = imagecolorallocate($im,255,255,255);
  29.     $blue = imagecolorallocate($im,0,0,255);
  30.  
  31.     imagefill($im,0,0,0);
  32.  
  33.     for($i = 0;$i < $numlines;$i++){
  34.         $rawdata[$i] = explode(",", $lines[$i]); //rawdata[byte] beinhaltet ein array für den jeweiligen byte.  beispiel: $wert = rawdata[$byte][$zeile]
  35.     }
  36.  
  37.     $tval;
  38.  
  39.     //für min & max wert bestimmung.
  40.     $minval = 99999;
  41.     $maxval = -99999;
  42.     $minposx = 0;
  43.     $minposy = 0;
  44.     $maxposx = 0;
  45.     $maxposy = 0;
  46.     $maxval2 = -99999;
  47.     $minval2 = 99999;
  48.  
  49.    
  50.  
  51.     for($i=0;$i<$numlines;$i++){
  52.         $val2 = $rawdata[$i][$val];
  53.         if($val2 >= $maxval){$maxval = $val2;}
  54.         if($val2 <= $minval){$minval = $val2;}
  55.         if(!$minval){$minval =0;}
  56.     }
  57.  
  58.     $nullval = 0;
  59.     if($val == 19){
  60.         imagettftext ($im,20,0,32,128,$gray, "arial.ttf", "Byte 20 isnt a Byte. its the recording time in seconds. range 0 to ".$numlines);
  61.     }elseif($val >19 || $val < 0){
  62.         imagettftext ($im,30,0,32,128,$gray, "arial.ttf", "Your value ". $val+1 ." isnt valid, it goes from 1 to 20!");
  63.     }else{
  64.         imagettftext ($im,20,0,32,128,$gray, "arial.ttf", "Value ranging from ".$minval." to ".$maxval." on byte ".($val+1));
  65.         imagettftext ($im,20,0,32,256,$gray, "arial.ttf", "".$annotation);
  66.         for($i = 0;$i < $numlines;$i++){
  67.             $value = $rawdata[$i][$val];
  68.             $value2 = $rawdata[$i-1][$val];
  69.            
  70.             //falls länger eine 0 kommt zum sepperieren mehrere aneinandergefügter daten.
  71.             if($rawdata[$i][1] == 0){
  72.                 $nullval++;
  73.                 $txt = true;
  74.             }else{
  75.                 $nullval=0;
  76.             }
  77.  
  78.             if($nullval < 2){
  79.                 if($txt == true && $nullval < 1){
  80.                     imagestring($im,5,($i*3)-150,250,"NEUER DATENSATZ",$white);
  81.                     $txt = false;
  82.                 }
  83.                 imageline($im,($i*3)+10,280-$value2,($i*3)+11,280-$value,$white);
  84.             }
  85.  
  86.             $tval++;
  87.  
  88.             if($value > $maxval2)
  89.             {
  90.                 $maxval2 = $value;
  91.                 $maxposx=$i*3;
  92.                 $maxposy=260-$value;
  93.             }
  94.  
  95.             if($value < $minval2)
  96.             {
  97.                 $minval2 = $value;
  98.                 $minposx=($i*3)+5;
  99.                 $minposy=280-$value;
  100.             }
  101.  
  102.  
  103.             if($tval >= 100){ // jede 100 datensätze eine linie und text.
  104.  
  105.                 imagestring($im,5,$maxposx,$maxposy,"". $maxval2,$red);
  106.                 imagestring($im,5,$minposx,$minposy,"". $minval2,$blue);
  107.  
  108.                 $maxval2 = -99999;
  109.                 $minval2 = 99999;
  110.                 $minposx = 0;
  111.                 $minposy = 0;
  112.                 $maxposx = 0;
  113.                 $maxposy = 0;
  114.  
  115.                 //imagestring($im,5,($i*3),280-$value,"". $value,$white);
  116.                 imageline($im,($i*3),0,($i*3),$imheight-10,$gray);
  117.                 imagestring($im,3,($i*3)-10,285,$i+1,$white);
  118.                 $tval = 0;
  119.             }
  120.  
  121.  
  122.         }
  123.  
  124.     }
  125.  
  126.    
  127.  
  128.     imageline($im,0,1,3600,1,$white);
  129.     imageline($im,0,$imheight,3600,$imheight,$white);
  130.  
  131.     imagestring($im,5,1,270,"0",$white);
  132.     imagestring($im,5,1,20,"255",$white);
  133.  
  134.     imagepng($im);
  135.     imagedestroy($im);
  136.  
  137.     fclose($fh);
  138.  
  139. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement