cry of war Posted August 10, 2007 Share Posted August 10, 2007 I am making a MMORPG and I need a really simple graph for showing how much unit next level up health and so on. I have searched the web and all I can find is really complicated line graphs or bar graphs that have more then one bar or lines. I just need to be able to make the bar so say i had 50/100 health it would be 50% full. Any help to point me in the right direction would be great because i have no idea how to do this otherwise. Quote Link to comment https://forums.phpfreaks.com/topic/64280-graphing/ Share on other sites More sharing options...
BillyBoB Posted August 10, 2007 Share Posted August 10, 2007 Hello i hope this is good enough for you there is a small white border with it. <?php header("Content-type: image/png"); $im = imagecreatefrompng("health.png"); $y1 = 1; $y2 = 18; $red = imagecolorallocate($im, 255, 0, 0); if($_GET['hp']) { $x = imagesx($im); $x = $x - 2; $hpleft = $_GET['hp']/100; $px = $x * $hpleft; imagefilledrectangle($im, 1, $y1, $px, $y2, $red); }else{ $x = imagesx($im); $x = $x - 2; $hpleft = 100/100; $px = $x * $hpleft; imagefilledrectangle($im, 1, $y1, $px, $y2, $red); } imagepng($im); ?> thats all the code just make a pic width of what you would like and height of 20. Call it health.png change the url to name.php?hp=(percentage) Heres what i came up with: http://dreamshowstudios.net/images.php?hp=100 if you want you can download the pic. http://dreamshowstudios.net/health.png Quote Link to comment https://forums.phpfreaks.com/topic/64280-graphing/#findComment-320560 Share on other sites More sharing options...
cry of war Posted August 10, 2007 Author Share Posted August 10, 2007 thats perfect any way to make that go vertical also? Quote Link to comment https://forums.phpfreaks.com/topic/64280-graphing/#findComment-320575 Share on other sites More sharing options...
BillyBoB Posted August 10, 2007 Share Posted August 10, 2007 like flip the whole thing vertical? Quote Link to comment https://forums.phpfreaks.com/topic/64280-graphing/#findComment-320576 Share on other sites More sharing options...
cry of war Posted August 10, 2007 Author Share Posted August 10, 2007 yeah instead of --- | | | Quote Link to comment https://forums.phpfreaks.com/topic/64280-graphing/#findComment-320583 Share on other sites More sharing options...
BillyBoB Posted August 10, 2007 Share Posted August 10, 2007 Ok here ya go: <?php header("Content-type: image/png"); $im = imagecreatefrompng("health.png"); $x1 = 1; $x2 = 18; $red = imagecolorallocate($im, 255, 0, 0); if($_GET['hp']) { if($_GET['hp']!=0) { $y = imagesy($im); $y = $y - 2; $hpleft = $_GET['hp']/100; $py = $y * $hpleft; imagefilledrectangle($im, $x1, 1, $x2, $py, $red); } }else{ if($_GET['hp']!=0) { $y = imagesy($im); $y = $y - 2; $hpleft = 100/100; $py = $y * $hpleft; imagefilledrectangle($im, $x1, 1, $x2, $py, $red); } } imagepng($im); ?> i did a couple of additions to it. same links tho http://dreamshowstudios.net/images.php?hp=100 if you want you can download the pic. http://dreamshowstudios.net/health.png Quote Link to comment https://forums.phpfreaks.com/topic/64280-graphing/#findComment-320586 Share on other sites More sharing options...
cry of war Posted August 10, 2007 Author Share Posted August 10, 2007 Thanks again your a life saver =-) Quote Link to comment https://forums.phpfreaks.com/topic/64280-graphing/#findComment-320588 Share on other sites More sharing options...
cry of war Posted August 13, 2007 Author Share Posted August 13, 2007 any idea how to put more then one graph on a page it keeps telling me that there is an error in the header heres the error <html> <title>Chart for life and such</title> <body> <table class=table_lines cellspacing="0" cellpadding="0" width="10%" border="0"> <tr> <td colspan="6" align="center">Status</td> </tr> <tr> <td colspan="2" align="center">???/???</td> <td colspan="2" align="center">???/???</td> <td colspan="2" align="center">???/???</td> </tr> <tr> <td align="center">H<br />e<br />a<br />l<br />t<br />h</td> <td> <font color=ff0000><br /> <b>Warning</b>: Cannot modify header information - headers already sent by (output started at C:\apache2triad\htdocs\try2.php:16) in <b>C:\apache2triad\htdocs\try2.php</b> on line <b>18</b><br /> </font>‰PNG and here is the code that i am using <html> <title>Chart for life and such</title> <body> <table class=table_lines cellspacing="0" cellpadding="0" width="10%" border="0"> <tr> <td colspan="6" align="center">Status</td> </tr> <tr> <td colspan="2" align="center">???/???</td> <td colspan="2" align="center">???/???</td> <td colspan="2" align="center">???/???</td> </tr> <tr> <td align="center">H<br />e<br />a<br />l<br />t<br />h</td> <td> <?php /*** vert ***/ header("Content-type: image/png"); $im1 = imagecreatefrompng("health.png"); $x1 = 1; $x2 = 18; $color1 = imagecolorallocate($im1, 255, 0, 0); if($_GET['health']) { if($_GET['health']!=0) { $y = imagesy($im1); $y = $y - 2; $healthleft = $_GET['health']/100; $py = $y * $healthleft; imagefilledrectangle($im1, $x1, 1, $x2, $py, $color1); } }else{ if($_GET['health']!=0) { $y = imagesy($im1); $y = $y - 2; $hpleft = 100/100; $py = $y * $hpleft; imagefilledrectangle($im1, $x1, 1, $x2, $py, $red); } } imagepng($im1); ?> </td> <td align="center">M<br />a<br />g<br />i<br />c<br />k<br />a</td> <td> <?php /*** vert ***/ header("Content-type: image/png"); $im2 = imagecreatefrompng("magicka.png"); $x1 = 1; $x2 = 18; $color2 = imagecolorallocate($im2, 255, 0, 0); if($_GET['magicka']) { if($_GET['magicka']!=0) { $y = imagesy($im2); $y = $y - 2; $magickaleft = $_GET['magicka']/100; $py = $y * $magickaleft; imagefilledrectangle($im2, $x1, 1, $x2, $py, $color2); } }else{ if($_GET['magicka']!=0) { $y = imagesy($im2); $y = $y - 2; $magickaleft = 100/100; $py = $y * $magickaleft; imagefilledrectangle($im2, $x1, 1, $x2, $py, $color2); } } imagepng($im2); ?> </td> <td align="center">S<br />t<br />a<br />m<br />i<br />n<br />a</td> <td> <?php /*** vert ***/ header("Content-type: image/png"); $im3 = imagecreatefrompng("stamina.png"); $x1 = 1; $x2 = 18; $color3 = imagecolorallocate($im3, 255, 0, 0); if($_GET['stamina']) { if($_GET['stamina']!=0) { $y = imagesy($im3); $y = $y - 2; $staminaleft = $_GET['stamina']/100; $py = $y * $staminaleft; imagefilledrectangle($im3, $x1, 1, $x2, $py, $color3); } }else{ if($_GET['stamina']!=0) { $y = imagesy($im3); $y = $y - 2; $staminaleft = 100/100; $py = $y * $staminaleft; imagefilledrectangle($im3, $x1, 1, $x2, $py, $red); } } imagepng($im3); ?> </td> </tr> Quote Link to comment https://forums.phpfreaks.com/topic/64280-graphing/#findComment-322587 Share on other sites More sharing options...
Barand Posted August 13, 2007 Share Posted August 13, 2007 assuming the image code to produce a bar is in health.php , put several on a page with <img src="health.php?hp=20"> <img src="health.php?hp=40"> <img src="health.php?hp=80"> Quote Link to comment https://forums.phpfreaks.com/topic/64280-graphing/#findComment-322638 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.