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...
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 ($img, 255, 255, 255); |
| 25 | $black = ImageColorAllocate ($img, 0, 0, 0); |
| 26 | $gray = ImageColorAllocate ($img, 250, 252, 255); |
| 27 | $gray2 = ImageColorAllocate ($img, 200, 210, 215); |
| 28 | $blue = ImageColorAllocate ($img, 80, 90, 95); |
| 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, $fontsize, 0, ($width/2)-14, 21, $gray2, $font, 12); |
| 35 | ImageTTFText($img, $fontsize, 0, ($width/2)-12, 23, $blue, $font, 12); |
| 36 | ImageTTFText($img, $fontsize, 0, ($width/2)-13, 22, $white, $font, 12); |
| 37 | ImageTTFText($img, $fontsize, 0, $width-23, ($height/2)-6, $gray2, $font, 3); |
| 38 | ImageTTFText($img, $fontsize, 0, $width-21, ($height/2)-4, $blue, $font, 3); |
| 39 | ImageTTFText($img, $fontsize, 0, $width-22, ($height/2)-5, $white, $font, 3); |
| 40 | ImageTTFText($img, $fontsize, 0, ($width/2)-8, $height-12, $gray2, $font, 6); |
| 41 | ImageTTFText($img, $fontsize, 0, ($width/2)-6, $height-10, $blue, $font, 6); |
| 42 | ImageTTFText($img, $fontsize, 0, ($width/2)-7, $height-11, $white, $font, 6); |
| 43 | ImageTTFText($img, $fontsize, 0, 11, ($height/2)-6, $gray2, $font, 9); |
| 44 | ImageTTFText($img, $fontsize, 0, 13, ($height/2)-4, $blue, $font, 9); |
| 45 | ImageTTFText($img, $fontsize, 0, 12, ($height/2)-5, $white, $font, 9); |
| 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)+2, 5, $blue); |
| 48 | ImageRectangleWithRoundedCorners($img, ($width/2)-9, ($height/2)-11, ($width/2)+5, ($height/2)+1, 5, $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 | ?> |
317 hits by 16 users in the last 30 minutes.