<?php
//
//   USE>
//
//   http://users.fs.cvut.cz/hlavac/t/tank1.php?t=1
//
//
header('Content-Type: image/png'); 
$im = @imagecreatefrompng('1.png');
$im1= @imagecreatefrompng('1.png');
// get tank number, otherwise 1>
$tn=1;
if(isset($_GET['t'])) 
{
$tn = $_GET['t']; 
 }
if ($tn<1)  $tn = 1;
if ($tn>5)  $tn = 5; 
//level from the database  
$level = 0;
// connect database ...
$link=mysqli_connect('147.32.164.26','alik','*****','alik')
or die('Error connecting database: '.mysqli_error($link) );
$re=mysqli_real_query($link,'select * from tanks where tank='.$tn.' order by cas desc limit 1;');
$result=mysqli_use_result($link);
$row=mysqli_fetch_assoc($result);
$level = $row['level'];
if ($level<0)  $level = 0;
if ($level>255)  $level = 255;   
$y1 = 164 - round( $level/255 *(164-18) );
for ($y=$y1; $y<=164; $y++)    {
   imagecopy($im,    $im1,   32,    $y,    32,    165,   50,     1);
    }
// Picture output
imagepng($im);

// Cleaning
mysqli_close($link);
imagedestroy($im);  
imagedestroy($im1);
?>