Renlok Posted June 4, 2007 Share Posted June 4, 2007 its first time trying to use GD and i dont really know what im doing but im trying to make a percentage bar, than once ive got that sorted out i would like to put the values of the bar over the top this is the code i tried with but all it does is display the url <?php //get bar percentage if( $_GET['real'] > 0){ $perc = ( $_GET['real'] / $_GET['max']) * 100; } else { $perc = 0; } // create image $per = imagecreate(90,10); //get needed colours $background = imagecolorallocate($per, 0xFF, 0xFF, 0xFF); $foreground = imagecolorallocate($per, 0x00, 0x8A, 0x01); $textcol = imagecolorallocate($per, 000, 000, 000); $border = imagecolorallocate($per, 0x99, 0x99, 0x99); //lenght of bar $bar_lenght = $perc * 0.9; //draw the bar imagefilledrectangle($per, 0, 0, $bar_lenght, 2, $foreground); imagerectangle($per, $bar_lenght+1, -2, 90, 10, $border); header("Content-type: image/png"); imagepng($per, '', 100); imagedestroy($per); ?> anyone have any ideas? Link to comment https://forums.phpfreaks.com/topic/54128-solved-gd-help/ Share on other sites More sharing options...
Renlok Posted June 4, 2007 Author Share Posted June 4, 2007 anyone? Link to comment https://forums.phpfreaks.com/topic/54128-solved-gd-help/#findComment-267784 Share on other sites More sharing options...
Barand Posted June 4, 2007 Share Posted June 4, 2007 One I prepared earlier This sample displays the bars <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <META http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <META http-equiv="content-language" content="en"> <META name="author" content="Barand"> <META name="generator" content="PHPEd 4.5"> <title>Bar sample</title> </head> <body> <table width="300" border='1'> <tr> <td> Item A </td> <td> 20% </td> <td> <img src='bar.php?val=20&max=100'> </td> </tr> <tr> <td> Item B </td> <td> 40% </td> <td> <img src='bar.php?val=40&max=100'> </td> </tr> <tr> <td> Item C </td> <td> 30% </td> <td> <img src='bar.php?val=30&max=100'> </td> </tr> <tr> <td> Item D </td> <td> 10% </td> <td> <img src='bar.php?val=10&max=100'> </td> </tr> </table> </body> </html> and this is the gd code ::bar.php:: <?php // set dimensions $w = 102; $h = 12; // create image $im = imagecreate($w, $h); // set colours to be used $bg = imagecolorallocate($im, 0xE0, 0xE0, 0xE0); $black = imagecolorallocate($im, 0x00, 0x00, 0x00); $barcolor = imagecolorallocate($im, 0xFF, 0x00, 0x00); // draw border imagerectangle($im, 0,0,$w-1,$h-1,$black); // get value and max value from query string $val = isset($_GET['val']) ? $_GET['val'] : 0; $max = isset($_GET['max']) ? $_GET['max'] : 100; // calculate dimensions of inner bar $barw = $max ? floor(($w-2) * $val / $max) : 0; $barh = $h - 2; // draw inner bar if ($barw) imagefilledrectangle($im, 1, 1, $barw, $barh, $barcolor); // send image header header("content-type: image/png"); // send png image imagepng($im); imagedestroy($im); ?> Link to comment https://forums.phpfreaks.com/topic/54128-solved-gd-help/#findComment-267823 Share on other sites More sharing options...
Renlok Posted June 4, 2007 Author Share Posted June 4, 2007 thats just what i needed cheers also one more thing how would i go around added an image over the top of the bar? its just a gradient thing to make make it look less flat Link to comment https://forums.phpfreaks.com/topic/54128-solved-gd-help/#findComment-267847 Share on other sites More sharing options...
Barand Posted June 4, 2007 Share Posted June 4, 2007 perhaps www.php.net/imagecopymerge Link to comment https://forums.phpfreaks.com/topic/54128-solved-gd-help/#findComment-267855 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.