| AND OR | string words | *

image editing

|

analog GD clock


this little snippet makes a real-time analog clock with the GD library.
don't assume that it's good for the server though...


function ImageRectangleWithRoundedCorners( ) [ line 14 ]


function Animation( ) [ line 68 ]



full source of analog GD clock [ line 1 - 77 ] | download analog GD clock

1    <?php
2   $width 210;
3   $height 210;
4   if(isset($_GET['doit']))
5   {
6       $font 'path/to/the/font_file.ttf';
7       $fontsize 12;
8       $smfontsize 8;
9       /*---------------------------------------------*/
10       $array['hour'] = 0-(date('h')*30)-270;
11       $array['min'] = 0-(date('i')*6)-270;
12       $array['sec'] = 0-(date('s')*6)-270;
13       /*---------------------------------------------*/
14       function ImageRectangleWithRoundedCorners(&$im$x1$y1$x2$y2$radius$color)
15       {
16           imagefilledrectangle($im$x1+$radius$y1$x2-$radius$y2$color);
17           imagefilledrectangle($im$x1$y1+$radius$x2$y2-$radius$color);
18           imagefilledellipse($im$x1+$radius$y1+$radius$radius*2$radius*2$color);
19           imagefilledellipse($im$x2-$radius$y1+$radius$radius*2$radius*2$color);
20           imagefilledellipse($im$x1+$radius$y2-$radius$radius*2$radius*2$color);
21           imagefilledellipse($im$x2-$radius$y2-$radius$radius*2$radius*2$color);
22       }
23       $img imagecreatetruecolor($width,$height);
24       $white ImageColorAllocate ($img255255255);
25       $black ImageColorAllocate ($img000);
26       $gray ImageColorAllocate ($img250252255);
27       $gray2 ImageColorAllocate ($img200210215);
28       $blue ImageColorAllocate ($img809095);
29       ImageRectangleWithRoundedCorners(&$img,1,1,$width-3,$height-3,10,$blue);
30       ImageRectangleWithRoundedCorners(&$img,3,3,$width-1,$height-1,10,$gray2);
31       ImageRectangleWithRoundedCorners(&$img,2,2,$width-2,$height-2,10,$white);
32       ImageRectangleWithRoundedCorners(&$img,4,4,$width-4,$height-4,10,$gray);
33       imagecolortransparent($img,$black);
34       ImageTTFText($img$fontsize0, ($width/2)-1421$gray2$font12);
35       ImageTTFText($img$fontsize0, ($width/2)-1223$blue$font12);
36       ImageTTFText($img$fontsize0, ($width/2)-1322$white$font12);
37       ImageTTFText($img$fontsize0$width-23, ($height/2)-6$gray2$font3);
38       ImageTTFText($img$fontsize0$width-21, ($height/2)-4$blue$font3);
39       ImageTTFText($img$fontsize0$width-22, ($height/2)-5$white$font3);
40       ImageTTFText($img$fontsize0, ($width/2)-8$height-12$gray2$font6);
41       ImageTTFText($img$fontsize0, ($width/2)-6$height-10$blue$font6);
42       ImageTTFText($img$fontsize0, ($width/2)-7$height-11$white$font6);
43       ImageTTFText($img$fontsize011, ($height/2)-6$gray2$font9);
44       ImageTTFText($img$fontsize013, ($height/2)-4$blue$font9);
45       ImageTTFText($img$fontsize012, ($height/2)-5$white$font9);
46       ImageRectangleWithRoundedCorners($img, ($width/2)-10, ($height/2)-12, ($width/2)+4, ($height/2), 5$gray2);
47       ImageRectangleWithRoundedCorners($img, ($width/2)-8, ($height/2)-10, ($width/2)+6, ($height/2)+25$blue);
48       ImageRectangleWithRoundedCorners($img, ($width/2)-9, ($height/2)-11, ($width/2)+5, ($height/2)+15$white);
49       $hstr '.  '.date('h').' hours';
50       ImageTTFText($img$smfontsize$array['hour'], ($width/2)-1, ($height/2)-2$blue$font$hstr);
51       ImageTTFText($img$smfontsize$array['hour'], ($width/2)-3, ($height/2)-4$gray2$font$hstr);
52       ImageTTFText($img$smfontsize$array['hour'], ($width/2)-2, ($height/2)-3$white$font$hstr);
53       $mstr '.  '.date('i').' minutes';
54       ImageTTFText($img$smfontsize$array['min'], ($width/2)-1, ($height/2)-2$blue$font$mstr);
55       ImageTTFText($img$smfontsize$array['min'], ($width/2)-3, ($height/2)-4$gray2$font$mstr);
56       ImageTTFText($img$smfontsize$array['min'], ($width/2)-2, ($height/2)-3$white$font$mstr);
57       $sstr '.  '.date('s').' seconds';
58       ImageTTFText($img$smfontsize$array['sec'], ($width/2)-1, ($height/2)-2$blue$font$sstr);
59       ImageTTFText($img$smfontsize$array['sec'], ($width/2)-3, ($height/2)-4$gray2$font$sstr);
60       ImageTTFText($img$smfontsize$array['sec'], ($width/2)-2, ($height/2)-3$white$font$sstr);
61       header('Content-type: image/png');
62       imagepng($img);
63       imagedestroy($img);
64   }else{
65       echo '
66   <img name="clock" src="'.$_SERVER['PHP_SELF'].'?doit=yes" width="'.$width.'" height="'.$height.'">
67   <script type="text/javascript"><!--
68       function Animation()
69       {
70           document.clock.src = "'.$_SERVER['PHP_SELF'].'?doit="+new Date();
71           window.setTimeout("Animation()",1000);
72       }
73       window.setTimeout("Animation()",1000);
74   //--></script>
75   ';
76   }
77   ?>



2 hits by 2 users in the last 30 minutes.