Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //read file in ?file= parameter
- if(isset($_GET["im"])){
- header("Content-type: image/png");
- }
- $val = $_GET["val"]-1; //Byte 1 - 19
- $annotation = $_GET["alt"]; //comment
- $fh = fopen($_GET["file"],"r");
- $data = fread($fh,filesize($_GET["file"]));
- $lines = explode("\n",$data);
- $numlines = count($lines); // wie viel zeilen die data.log hat.
- //graph
- $imheight = 300;
- //$im = imagecreatefrompng("empty.png"); // wird nur für transparent gebraucht, unnötig
- $im = imagecreate(($numlines*3)+32,$imheight);
- //colors
- $black = imagecolorallocate($im,0,0,0);
- $red = imagecolorallocate($im,255,0,0);
- $gray = imagecolorallocate($im,65,55,55);
- $white = imagecolorallocate($im,255,255,255);
- $blue = imagecolorallocate($im,0,0,255);
- imagefill($im,0,0,0);
- for($i = 0;$i < $numlines;$i++){
- $rawdata[$i] = explode(",", $lines[$i]); //rawdata[byte] beinhaltet ein array für den jeweiligen byte. beispiel: $wert = rawdata[$byte][$zeile]
- }
- $tval;
- //für min & max wert bestimmung.
- $minval = 99999;
- $maxval = -99999;
- $minposx = 0;
- $minposy = 0;
- $maxposx = 0;
- $maxposy = 0;
- $maxval2 = -99999;
- $minval2 = 99999;
- for($i=0;$i<$numlines;$i++){
- $val2 = $rawdata[$i][$val];
- if($val2 >= $maxval){$maxval = $val2;}
- if($val2 <= $minval){$minval = $val2;}
- if(!$minval){$minval =0;}
- }
- $nullval = 0;
- if($val == 19){
- imagettftext ($im,20,0,32,128,$gray, "arial.ttf", "Byte 20 isnt a Byte. its the recording time in seconds. range 0 to ".$numlines);
- }elseif($val >19 || $val < 0){
- imagettftext ($im,30,0,32,128,$gray, "arial.ttf", "Your value ". $val+1 ." isnt valid, it goes from 1 to 20!");
- }else{
- imagettftext ($im,20,0,32,128,$gray, "arial.ttf", "Value ranging from ".$minval." to ".$maxval." on byte ".($val+1));
- imagettftext ($im,20,0,32,256,$gray, "arial.ttf", "".$annotation);
- for($i = 0;$i < $numlines;$i++){
- $value = $rawdata[$i][$val];
- $value2 = $rawdata[$i-1][$val];
- //falls länger eine 0 kommt zum sepperieren mehrere aneinandergefügter daten.
- if($rawdata[$i][1] == 0){
- $nullval++;
- $txt = true;
- }else{
- $nullval=0;
- }
- if($nullval < 2){
- if($txt == true && $nullval < 1){
- imagestring($im,5,($i*3)-150,250,"NEUER DATENSATZ",$white);
- $txt = false;
- }
- imageline($im,($i*3)+10,280-$value2,($i*3)+11,280-$value,$white);
- }
- $tval++;
- if($value > $maxval2)
- {
- $maxval2 = $value;
- $maxposx=$i*3;
- $maxposy=260-$value;
- }
- if($value < $minval2)
- {
- $minval2 = $value;
- $minposx=($i*3)+5;
- $minposy=280-$value;
- }
- if($tval >= 100){ // jede 100 datensätze eine linie und text.
- imagestring($im,5,$maxposx,$maxposy,"". $maxval2,$red);
- imagestring($im,5,$minposx,$minposy,"". $minval2,$blue);
- $maxval2 = -99999;
- $minval2 = 99999;
- $minposx = 0;
- $minposy = 0;
- $maxposx = 0;
- $maxposy = 0;
- //imagestring($im,5,($i*3),280-$value,"". $value,$white);
- imageline($im,($i*3),0,($i*3),$imheight-10,$gray);
- imagestring($im,3,($i*3)-10,285,$i+1,$white);
- $tval = 0;
- }
- }
- }
- imageline($im,0,1,3600,1,$white);
- imageline($im,0,$imheight,3600,$imheight,$white);
- imagestring($im,5,1,270,"0",$white);
- imagestring($im,5,1,20,"255",$white);
- imagepng($im);
- imagedestroy($im);
- fclose($fh);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement