Jump to content

Generating a Segmented Signal Strength Graph?


signal

Recommended Posts

 

I'm trying to figure out the best way to generate a signal strength graphic much like wifi tools or mobile phones have.

 

These are usually a scaled segmented graphic that go from small to large segments.

How many segments are "on" is based on a single value.

 

Using a bar graph tool seems overkill and doesn't present the scaleable/segmented effect.

A "progress" bar doesn't seem to be the right direction either.

 

Any ideas on how to go about this?

Or does a class/extension exist for it?

 

Thanks.

 

 

 

Using the image function to draw multiple bars (solid or not) per "meter" seems it would be a bit intensive.

 

Here's is an example from the Intel PROSet/Wireless software.

proset_splash.jpg

 

The green signal strength bar graph on the left side is what I'm after.

Note the bars are always there but being solid or not is based on a single value.

 

I suppose the easiest thing would be to generate 6 static images (or more if more segments are used).

 

 

Dynamic GD version

 

:: ssm.php ::

 

<?php
$im = imagecreate(42,32);
$white = imagecolorallocate($im, 0xFF,0xFF,0xFF);
$sig =   imagecolorallocate($im, 0xFF,0x00,0x00); 
$nosig = imagecolorallocate($im, 0x00,0xFF,0x00);
$black = imagecolorallocate($im, 0x00,0x00,0x00);

$ss = $_GET['ss'];      // 0 to 5


    $barheight = array (10, 15, 20, 25, 30); 
    $barwidth = 5;
    $gap = 4;
for ($b=0; $b<5; $b++) {
    
    $ht = $barheight[$b];
    $x1 = $b * ($barwidth+$gap);      // determine bar position
    $x2 = $x1+$barwidth;
    $y2 = 31;
    $y1 = $y2 - $ht;
    $col = $ss > $b ? $sig : $nosig;  // determine color of this bar
    imagefilledrectangle($im, $x1, $y1, $x2, $y2, $col);
    imagerectangle($im, $x1, $y1, $x2, $y2, $black);
}

header("content-type: image/png");
imagepng($im);
imagedestroy($im);

?>

 

To view the images

 

:: ssm.html ::

<html>
<head>
<meta name="generator" content="PhpED Version 4.5 (Build 4513)">
<title>Signal strength</title>
<meta name="author" content="Barand">
</head>
<body>
<img src="ssm.php?ss=0"/> Signal strength 0<br />
<img src="ssm.php?ss=2"/> Signal strength 2<br />
<img src="ssm.php?ss=4"/> Signal strength 4<br />
</body>
</html>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.