Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
NEW SERVER - 11.9.2020 ... Retiring, March 2020 - sorry, you have missed our final public course.
The Coronavirus situation has lead us to suspend public training - which was on the cards anyway, with no plans to resume

Please ask about private 'maintenance' training for Python, Tcl, Perl, PHP, Lua, etc
Happily continuing private consultancy / programming work
Draw hands on a clock
Additional PHP Material example from a Well House Consultants training course
More on Additional PHP Material [link]

This example is described in the following article(s):
   • Drawing hands on a clock face - PHP - [link]

If you're searching for a page where you can try this code, select here

Source code: hands.php Module: H999

/* the hands function draws the hands of a clock (and if
requested a simple clock face too) onto an image in PHP
using the GD module. */

# $h - hour of day
# $m - minute of hour
# $fn - jpg image onto which hands are to be added
# $l - length in pixels of minute hand (hour hand is shorter)
# $x and $y - centre of clock
# $a - flag. 0 - just hands. 1 - draw circle around clockface
#      2 and 3 - filled clock face, different colours

function hands($h=10$m=14$fn="xx_yy.jpg",
$l=150$x=200$y=200$a=0) {

$angle_min =  90.0 $m 6.0;  # minute to degrees
$angle_hour 90.0 - ($h $m 60.0) *30.0;

$minx $l cos($angle_min 57.295779);
$miny $l sin($angle_min 57.295779);
$hourx 0.65 $l cos($angle_hour 57.295779);
$houry 0.65 $l sin($angle_hour 57.295779);

$hh[0] = $x 0.10 $hourx# backend of hand
$hh[1] = $y 0.10 $houry;

$hh[2] = $x 0.10 $houry# side of hand
$hh[3] = $y 0.10 $hourx;

$hh[4] = $x $hourx;   # tip if hand
$hh[5] = $y $houry;

$hh[6] = $x 0.10 $houry;
$hh[7] = $y 0.10 $hourx# side of hand

$mm[0] = $x 0.05 $minx;
$mm[1] = $y 0.05 $miny;

$mm[2] = $x 0.05 $miny;
$mm[3] = $y 0.05 $minx;

$mm[4] = $x $minx;
$mm[5] = $y $miny;

$mm[6] = $x 0.05 $miny;
$mm[7] = $y 0.05 $minx;

$im imagecreatefromjpeg($fn);
$pink imagecolorallocate($im,255,30,90);
$blue imagecolorallocate($im,240,90,30);
        if (
$a 3) {
$brown imagecolorallocate($im,80,80,10);
        } else {
$brown imagecolorallocate($im,80,20,80);
        if (
$a )
        if (
$a == 1)
header("content-type: image/jpeg");
if (
is_string($_REQUEST[h])) {
$h $_REQUEST[h];
$m $_REQUEST[m];
$l $_REQUEST[l];
$fn $_REQUEST[imname];
$x $_REQUEST[x];
$y $_REQUEST[y];
$a $_REQUEST[a];
} else {
$now time() + 3600# PST server, GMT to report
$h date("g",$now)%12;
$m date("i",$now);

Learn about this subject
This module and example are covered on the following public courses:
 * Learning to program in PHP
 * PHP Programming
 * PHP Programming
 * Learning to program in PHP
Also available on on site courses for larger groups

Books covering this topic
Yes. We have over 700 books in our library. Books covering PHP are listed here and when you've selected a relevant book we'll link you on to Amazon to order.

Other Examples
This example comes from our "Additional PHP Material" training module. You'll find a description of the topic and some other closely related examples on the "Additional PHP Material" module index page.

Full description of the source code
You can learn more about this example on the training courses listed on this page, on which you'll be given a full set of training notes.

Many other training modules are available for download (for limited use) from our download centre under an Open Training Notes License.

Other resources
• Our Solutions centre provides a number of longer technical articles.
• Our Opentalk forum archive provides a question and answer centre.
The Horse's mouth provides a daily tip or thought.
• Further resources are available via the resources centre.
• All of these resources can be searched through through our search engine
• And there's a global index here.

Web site author
This web site is written and maintained by Well House Consultants.

Purpose of this website
This is a sample program, class demonstration or answer from a training course. It's main purpose is to provide an after-course service to customers who have attended our public private or on site courses, but the examples are made generally available under conditions described below.

Conditions of use
Past attendees on our training courses are welcome to use individual examples in the course of their programming, but must check the examples they use to ensure that they are suitable for their job. Remember that some of our examples show you how not to do things - check in your notes. Well House Consultants take no responsibility for the suitability of these example programs to customer's needs.

This program is copyright Well House Consultants Ltd. You are forbidden from using it for running your own training courses without our prior written permission. See our page on courseware provision for more details.

Any of our images within this code may NOT be reused on a public URL without our prior permission. For Bona Fide personal use, we will often grant you permission provided that you provide a link back. Commercial use on a website will incur a license fee for each image used - details on request.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2020: 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/resources/ex.php • PAGE BUILT: Sun Oct 11 14:50:09 2020 • BUILD SYSTEM: JelliaJamb