Page 1 of 1

Adding a Max to a graphic bar[topic solved]

Posted: Sun Aug 19, 2007 12:38 pm
by SirChick
I have a bar which i need to change its max using fields from my table but i need the size and height to be the same..example of what i mean:

Max E - 100
Current E - 50
Green will be half way on the bar.

Max E - 150 (still the same length physically how ever as the 100 E bar)
Current E - 50
Green will be a third of the way up on the bar.


so i have:

maxE and currentE i need the width and height always at 76 wide and 5 height. But the green to red need to be scalled differently if maxE is larger.


this is what i got so far:

Code: Select all

//the two fields from user table set as variables
$MaxEnergy = $row["MaxEnergy"];
$CurrentEnergy = $row["CurrentEnergy"];

$height = 5;
$width = 76;
$im = Imagecreatetruecolor($width, $height);
$red = Imagecolorallocate($im, 400, 0, 10);
$green = Imagecolorallocate($im, 0, 400, 10);
imagefill($im, 0, 0, $red);
imagefilledrectangle($im, 0, 0, $CurrentEnergy, $height, $green);
header("Content-type: image/png");
Imagepng($im);
Imagedestroy($im);
the problem at the moment is im unsure on where i should put my "Maximum E " into the script for it to work the way i need it to?

Posted: Sun Aug 19, 2007 12:58 pm
by feyd
Generally...

Code: Select all

($CurrentEnergy / $MaxEnergy) * $MaxWidth;

Posted: Sun Aug 19, 2007 1:05 pm
by SirChick
eh? :S

what would that equal ? The amount of current E ?

EDIT i understand now. got it working thankyou :)