Artykuły na każdy temat
<?php
$config = array('border' => 60, 'size' => 40, 'space' => 15);
$size[0] = ($config['border'] * 2) + (6 * $config['size']) + (5 * $config['space']) + 1;
$size[1] = $config['border'] + (4 * $config['size']) + (3 * $config['space']) + 1;
$time = date('His');
$elements = array(2, 4, 3, 4, 3, 4);
for($h = 0; $h < 6; ++$h)
{
$binary_time[$h] = array_reverse(str_split(decbin($time[$h])));
}
$c = c();
$im = imagecreate($size[0], ($size[1] + $config['border']));
$background = imagecolorallocate($im, 255, 255, 255);
$color = imagecolorallocate($im, $c[0], $c[1], $c[2]);
for($x[0] = 0; $x[0] < 6; ++$x[0])
{
$x[1] = $config['border'] + ($x[0] * $config['size']) + ($x[0] * $config['space']);
$x[2] = $x[1] + $config['size'];
for($y[0] = ($elements[$x[0]] - 1); $y[0] >= 0; --$y[0])
{
$y[1] = $size[1] - ($y[0] * $config['size']) - ($y[0] * $config['space']) - 1;
$y[2] = $y[1] - $config['size'];
if($binary_time[$x[0]][$y[0]])
{
imagefilledrectangle($im, $x[1], $y[1], $x[2], $y[2], $color);
}
else
{
imagerectangle($im, $x[1], $y[1], $x[2], $y[2], $color);
}
}
}
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
// Auxiliary functions
function c()
{
// c() like get_color()?
$c = array(205, 0, 0);
if(isset($_GET['r']) && isset($_GET['g']) && isset($_GET['b']))
{
$r = v($_GET['r']);
$g = v($_GET['g']);
$b = v($_GET['b']);
if(is_int($r) && is_int($g) && is_int($b))
{
$c = array($r, $g, $b);
}
}
return $c;
}
function v($c)
{
// v() like validation()?
$c = (int)$c;
return ($c < 0 || $c > 255 ? false : $c);
}
?>
Wynikiem tego kodu jest coś takiego:
Komentarze
Dodaj komentarz