<?PHP
Header ("Content-type: image/jpeg");
// Create either from JPG or draw the face
$Image = $HTTP_GET_VARS["img"];
$im = "";
if (! empty ($Image))
$im = ImageCreateFromJPEG ($DOCUMENT_ROOT."/obj/textures/".$Image.".jpg");
if ($im == "")
{
$im = ImageCreate (256,256);
$UseImage = false;
}
else
$UseImage = true;
$sx = ImageSX ($im);
$sy = ImageSY ($im);
$cx = ($sx/2)-1;
$cy = ($sy/2)-1;
$VrDiff = intval ($HTTP_GET_VARS["vr"]);
$Roman = (($HTTP_GET_VARS["typ"] & 0x01) == 0x01);
$Nonumb = (($HTTP_GET_VARS["typ"] & 0x02) == 0x02);
$Raketa = (($HTTP_GET_VARS["typ"] & 0x04) == 0x04);
$sHands = $HTTP_GET_VARS["hs"] / 100.0;
$cHour = MyImageColor ($im, 0xd0, 0x10, 0x10, $HTTP_GET_VARS["hc"]);
$cMin = MyImageColor ($im, 0xf0, 0x30, 0x30, $HTTP_GET_VARS["mc"]);
$cNum = MyImageColor ($im, 0x80, 0x00, 0x00, $HTTP_GET_VARS["nc"]);
if (! $UseImage)
{
$cFrame = MyImageColor ($im, 0x00, 0x00, 0x00, $HTTP_GET_VARS["fc"]);
$cClock = MyImageColor ($im, 0xff, 0xff, 0xE0, $HTTP_GET_VARS["cc"]);
ImageFill ($im, 1, 1, $cClock);
ImageArc ($im, 127, 127, 256, 256, 0, 360, $cFrame);
ImageFill ($im, 0, 0, $cFrame);
ImageFill ($im, 255, 0, $cFrame);
ImageFill ($im, 0, 255, $cFrame);
ImageFill ($im, 255, 255, $cFrame);
}
// CLOCKFACE
if ($Raketa)
{
if (! $UseImage)
ImageString ($im, 5, 100, 60, "PAKETA", $cNum);
$sTime = (gmstrftime ("%H")-2+$VrDiff) % 24; // VRT24
$div = 12;
$anz = 24;
}
else
{
$sTime = (gmstrftime ("%I")-2+$VrDiff) % 12; // VRT12
$div = 6;
$anz = 12;
}
$mTime = intval(gmstrftime ("%M"));
$sTime += $mTime / 60;
if ($Roman)
{
if (! $Nonumb)
$aRoman = array ('I','II','III','IV','V','VI','VII','VIII','IX','X'
,'XI','XII','XII','XIII','XV','XVI','XVII','XVIII','XIX','XX'
,'XXI','XXII','XXIII','XIV');
$tsize=($Raketa?1:2);
}
else
$tsize = ($sy < 256 ? 2 : 5);
if (! $Nonumb)
for ($i=1; $i<=$anz; $i++)
{
$h = $i * pi() / $div;
$x0 = $sx/256*121.0 + $sx/256*110.0 * sin ($h);
$y0 = $sy/256*120.0 - $sy/256*110.0 * cos ($h);
if ($Roman)
ImageString ($im, $tsize, $x0, $y0, $aRoman[$i-1], $cNum);
else
ImageString ($im, $tsize, $x0, $y0, $i, $cNum);
}
// HOURS
$h = $sTime * pi() / $div;
$x0 = $cx + $sx/256*80.0 * sin ($h);
$y0 = $cy - $sy/256*80.0 * cos ($h);
$h = $sTime * pi() / $div + (.08 + $sHands);
$x1 = $cx + $sx/256*30.0 * sin ($h);
$y1 = $cy - $sy/256*30.0 * cos ($h);
$h = $sTime * pi() / $div - (.08 + $sHands);
$x2 = $cx + $sx/256*30.0 * sin ($h);
$y2 = $cy - $sy/256*30.0 * cos ($h);
$a = array ($cx, $cy, $x1, $y1, $x0, $y0, $x2, $y2);
ImageFilledPolygon ($im, $a, 4, $cHour);
// MINUTES
$h = $mTime * pi() / 30;
$x0 = $cx + $sx/256*120.0 * sin ($h);
$y0 = $cy - $sy/256*120.0 * cos ($h);
$h = $mTime * pi() / 30 + (.08 + $sHands);
$x1 = $cx + $sx/256*30.0 * sin ($h);
$y1 = $cy - $sy/256*30.0 * cos ($h);
$h = $mTime * pi() / 30 - (.08 + $sHands);
$x2 = $cx + $sx/256*30.0 * sin ($h);
$y2 = $cy - $sy/256*30.0 * cos ($h);
$a = array ($cx, $cy, $x1, $y1, $x0, $y0, $x2, $y2);
ImageFilledPolygon ($im, $a, 4, $cMin);
ImageJPEG ($im, "", 90);
ImageDestroy ($im);
// END MAIN =============
function MyImageColor ($im, $r, $g, $b, $hex="")
{
if (!empty ($hex))
{
$r = hexdec (substr ($hex, 0, 2));
$g = hexdec (substr ($hex, 2, 2));
$b = hexdec (substr ($hex, 4, 2));
}
ImageColorAllocate ($im, $r, $g, $b);
return (ImageColorClosest ($im, $r, $g, $b));
}
?>