Main Content
Drawing hands on a clock face - PHP Archive - Originally posted on "The Horse's Mouth" - 2007-05-19 12:04:27 - Graham Ellis
Would you like to draw clock face hands on to an image (such as the one shown here, with the time in UK when you called the page up!)? It's easier than you think using PHP's GD module.
Instead of supplying a fixed image in your <img> tag, provide the URL of a PHP script that reads an image and adds the hands - like I've done to the left here. I've even provided the source code - here so you can do something similar if you wish!
This very example is also used on our site clock which generates one image per minute ... and it will be a long time before we have all the images we need without using the PHP "cheat" I've introduced on this page.
Some other articles
H999 - Additional PHP Material Image indexer / thumbnail display scripts in PHP Catchable fatal error in PHP ... How to catch, and alternative solutions such as JSON Arrays of arrays - or 2D arrays. How to program tables. Exception handling in PHP If nothing, make it nothing. Extra PHP Examples PHP Techniques - a workshop Flipping images on your web page Script to present commonly used images - PHP Copyright and theft of images, bandwidth and members. More PHP sample and demonstration programs Ordnance Survey Grid Reference to Latitude / Longitude Converting from postal address to latitude / longitude Controlling and labelling Google maps via PHP PHP Standalone - keyboard to screen This article Drawing dynamic graphs in PHP Sorting people by name in PHP Parallel processing in PHP Dates, times, clickable diarys in PHP Display an image from a MySQL database in a web page via PHP Syntax checking in PHP Reporting on the 10 largest files or 10 top scores PHP - a team member leaves Check your user is human. Have him retype a word in a graphic Hot answers in PHP Presentation, Business and Persistence layers in Perl and PHP PHP Image viewing application PHP - setting sort order with an associative array Merging pictures using PHP and GD Running a Perl script within a PHP page Double Dollars in PHP Stand alone PHP programs Time calculation in PHP the array returned by preg_match_all More maps Ordnance Survey - using a 'Get a map' What and why for the epoch PHP and natural sorting H309 - Maps, Graphics and Geographics Image indexer / thumbnail display scripts in PHP Adding a PHP build option, rotating an image based on camera data, and a new look at thumbnails in PHP The changing face of Christmas Where are you? How to write a geosensitive application Fpdf - generating .pdf documents easily from your PHP program QR codes with marketing logos embedded QR codes - graphics images that provide quick phone links UK Mapping Data - and more to come - under government Open Data measures Needle in a haystack - finding the web server overload Computer Graphics in PHP - World (incoming data) to Pixel (screen) conversion Finding and diverting image requests from rogue domains An image from a website that occasionally comes out as hyroglyphics Server logs - drawing a graph of gathered data Protecting your images from use out of context Uploading a document or image to its own URL via a browser Redirecting to your main domain for correct security keys Reducing image size on digital photos - PHP Dynamic / changing images on your web page Geocoding - converting address to latitude / Longitude with PHP via Google World Flags in your PHP pages Images for Christmas Making it all worthwhile Ever had One of THOSE mornings? Dynamic maps / geographics in PHP All around the world? addslashes v mysql_real_escape_string in PHP Gant charts - drawing them with a PHP script Ordnance Survey Grid Reference to Latitude / Longitude Converting from postal address to latitude / longitude Controlling and labelling Google maps via PHP This article Drawing dynamic graphs in PHP Display an image from a MySQL database in a web page via PHP PHP Image viewing application Merging pictures using PHP and GD Ordnance Survey - using a 'Get a map' H115 - Designing PHP-Based Solutions: Best Practice Real life PHP application using our course training MVC example Using an MVC structure - even without a formal framework Learning to program - comments, documentation and test code We not only teach PHP and Python - we teach good PHP and Python Practice! Even early on, separate out your program from your HTML! Filtering PHP form inputs - three ways, but which should you use? PHP sessions - a best practice teaching example Injection Attacks - PHP, SQL, HTML, Javascript - and how to neutralise them Separating program and artwork in PHP - easier maintainance, and better for the user How to build a test harness into your PHP Not just a PHP program - a good web application Adding a newsfeed for your users to a multipage PHP application Improving the structure of your early PHP programs Refactoring - a PHP demo becomes a production page Defensive coding techniques in PHP? PHP Techniques - a workshop Short and sweet and sticky - PHP form input Software to record day to day events and keep an action list Efficient PHP applications - framework and example A story about benchmarking PHP Ordnance Survey Grid Reference to Latitude / Longitude Converting from postal address to latitude / longitude Controlling and labelling Google maps via PHP Using a MySQL database to control mod_rewrite via PHP Easy handling of errors in PHP Resetting session based tests in PHP This article Painting a masterpiece in PHP Good Programming practise - where to initialise variables Back button - ensuring order are not submitted twice (PHP) Learning to write secure, maintainable PHP Maintainable code - some positive advice Code quality counts Global, Superglobal, Session variables - scope and persistance in PHP PHP - good coding practise and sticky radio buttons Reporting on the 10 largest files or 10 top scores Giving the researcher power over database analysis Merging pictures using PHP and GD Robust checking of data entered by users A year on - should we offer certified PHP courses Code and code maintainance efficiency Putting a form online Crossfertilisation, PHP to Python Short underground journeys and a PHP book G912 - Photography for the Web That spec is a kingfisher ... How far is something pictured from the camera? Catering in Syracuse, the Saigon Cafe, stolen images and Christmas Hotlinked images onto adult material sites Re-using our pictures Leaping dog, Leaping horse, copyright of old masters Trowbridge - a missed opportunity? Melksham - into the breach? Comparison - with and without flash Old pictures and comparisons What colour is the season? Ongoing Image Copyright Issues, PHP and MySQL solutions Using PHP to upload images / Store on MySQL database - security questions This article What shape is your shake? Themes for the web site PHP Image upload script Telling a story in different ways Display an image from a MySQL database in a web page via PHP My projector has a photo-id PHP Image viewing application Merging pictures using PHP and GD Keep that image small The relevance of the hairy woodpecker Published Photographer What makes a professional photographer?