VarjuOrg

Linux / Windows – what’s the difference…

PHP: Graafiline % pilt lehele

Image link:

<img alt="" src="bar.php?val=10&amp;max=100" />


bar.php

<?php
// set dimensions
$w = 500; $h = 12;

// create image
$im = imagecreate($w, $h);

// set colours to be used
$bg = imagecolorallocate($im, 0xFF, 0x00, 0x00);
$black = imagecolorallocate($im, 0x00, 0x00, 0x00);
$barcolor = imagecolorallocate($im, 120, 139, 0);

// 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'] : 500;

// 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);
?>

, ,

Leave a Reply

Your email address will not be published.