Jump to content

Hey Image Thing


burnside

Recommended Posts

Hello, i really dont know how to explane this but ill try best i can, I am making a script where if you have say 100 points but only 10 left it will show you in a images like a bar line etc ... i have tried but it doesnt seem to do what i want sorry if its not much help.

 $percent = $info[points] / $info[points_left];
$percent = $percent * 100;
$percent = round($percent);
$leftpercent = 100 - $percent;
$imagesss = "<tr><Td width=35 bgcolor=gray><img src=img\left.gif width=$percent height=10></td>"; 

echo $imagesss ; 

its showing the image but only at the current points left where i want it to show points and current points if you get me :\

Link to comment
Share on other sites

Do mean something like this one?

 

::bar.php::

<?php
// set dimensions
     $w = 102;
     $h = 10;
// create image
     $im = imagecreate($w, $h);
// set colours to be used
     $bg = imagecolorallocate($im, 0xE0, 0xE0, 0xE0);
     $black = imagecolorallocate($im, 0x00, 0x00, 0x00);
     $red  = imagecolorallocate($im, 0xFF, 0x00, 0x00);
     $green  = imagecolorallocate($im, 0x50, 0xB6, 0x30);  
// 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)
     {
        $barcolor = $val < 50 ? $red : $green;
     	imagefilledrectangle($im, 1, 1, $barw, $barh, $barcolor);
     }
// send image header
     header("content-type: image/png");
// send png image
     imagepng($im);
     imagedestroy($im);
?>

 

Call with something like

<?php
"echo <img src='bar.php?val=$current&max=$totalpoints'>";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.