Jump to content

Recommended Posts

  • Replies 72
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

In my code sample, change

<?php
  $pbar_width = (isset($_GET['w']))?$_GET['w']:10;
  echo '<span class="pbar" style="width:' . $pbar_width . '%;"> </span>';
?>

to

<?php
  $pbar_width = (isset($_GET['score']))?$_GET['score']:0;
  echo '<span class="pbar" style="width:' . $pbar_width . '%;"> </span>';
?>

 

Ken

It shouldn't be accessible. If you want it displayed like an image you have to use the www.php.net/image  image functions along with headers.

 

The CSS is to be on the page and it will not act like an image at all other than it sorta looks like one on the page.

I made a little function:

<?php
function createBar ($val, $max, $width='150', $height='15', $_col_bar=array(0,128,0), $_col_bg=array(255,250,255)) {
	$im = imagecreatetruecolor($width, $height);

	$col_bar = imagecolorallocate($im, $_col_bar[0], $_col_bar[1], $_col_bar[2]);
	$col_bg  = imagecolorallocate($im, $_col_bg[0], $_col_bg[1], $_col_bg[2]);

	imagefill($im, 0, 0, $col_bg);

	$min = $val / $max;
	$gr_min = $width * $min;

	$points = array(	0,	 0,
				$gr_min, 0,
				$gr_min, $height,
				0,	 $height);
	imagefilledpolygon($im, $points, 4, $col_bar);
	return $im;
}

header('Content-type: image/jpeg');
imagejpeg( createBar(200,300, 500, 20, array(255, 128, 0), array(230, 235, 255)) );
?>

Remember to only use that function without outputting anything (with echo, ...) and don't use plain-text (like html code, ...)

 

So how does it work:

createBar ($val, $max [, $width] [, $height=15] [, $_col_bar] [, $_col_bg])

$val = value (example 200)

$max = maximal value (example 300)

$width = width of bar in pixel (example 500)

$height = height of bar in pixel (example 20)

$_col_bar = color of bar (an array ... used like array (r, g, b))... so for example array(255, 128, 0) (orange))

$_col_bg = background color (the same as $_col_bar)

It shouldn't be accessible. If you want it displayed like an image you have to use the www.php.net/image  image functions along with headers.

 

The CSS is to be on the page and it will not act like an image at all other than it sorta looks like one on the page.

 

Then why does this one work?:

progress.php?score=30

I don't have the script of the image I showed. This is my code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Progress Bar</title>
<style>
.bar {
  display: block;
  width: 100px;
  border: 1px solid #B2B2B2;
  height: 8px;
}
.pbar {
  display: block;
  background-color: #FFE83F;
  float: left;
  height: 8px;
}
</style>
</head>
<body>
<div class="bar">
<?php
  $pbar_width = (isset($_GET['score']))?$_GET['score']:0;
  echo '<span class="pbar" style="width:' . $pbar_width . '%;"> </span>';
?>
<div style="clear:both;line-height:0.01em"> </div>
</div>
</body>
</html>

I used CSS and php, this is the code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Sander's Progress Bar</title>
<style>
.bar {
  display: block;
  width: 100px;
  border: 1px solid #B2B2B2;
  height: 8px;
}
.pbar {
  display: block;
  background-color: #AD0008;
  float: left;
  height: 8px;
}
</style>
</head>
<body>
<div class="bar">
<?php
  $pbar_width = (isset($_GET['score']))?$_GET['score']:0;
  echo '<span class="pbar" style="width:' . $pbar_width . '%;"> </span>';
?>
<div style="clear:both;line-height:0.01em"> </div>
</div>
</body>
</html>

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.