PHP Classes

PTX PHP GD Analog Clock: Render the time on analog clock as an image

Recommend this page to a friend!
  Info   View files Example   Demos   View files View files (18)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2023-12-03 (1 month ago) RSS 2.0 feedNot enough user ratingsTotal: 308 All time: 7,323 This week: 114Up
Version License PHP version Categories
ptx-clock 3GNU Lesser Genera...5.3HTML, PHP 5, Time and Date, Graphics
Description 

Author

This package can render the time on analog clock as an image.

It takes a time string with hours and minutes and renders an image displaying the pointers on circular analog clock.

There are two class variants: one that draws the clock pointers inside a circle and that renders the pointers over a base background image.

The resulting image can be saved to a PNG file or outputted as the current script output.

Innovation Award
PHP Programming Innovation award nominee
May 2015
Number 15
Many applications need to display the current time. They usually display a text string with the time, but sometimes it is nicer to display the time as a drawing of an analog clock.

This class can display the current time as an analog clock rendered as an image that can be displayed on the browser.

Manuel Lemos
Picture of Tomas Pavlatka
  Performance   Level  
Innovation award
Innovation award
Nominee: 2x

 

Example

<?php

require_once './vendor/autoload.php';

try {
   
$clock = new PTX\ClockCanvas();
   
$clock->draw();
   
$file_path = './cache/base.png';
   
$clock->to_file($file_path);
   
$clock->to_browser();
} catch(\
PTX\ClockException $e) {
    echo
$e->getMessage();
}


Details

PTX-Clock

PHP Class to create analog clock from the time given. I have a son and they are teaching him at school the clock. I though it would be great to create a simple game to help him out. This class is just a beginning of the whole idea.

Installation

You will need a composer to install autoload for you

composer install --no-dev

Example

require_once './vendor/autoload.php';

try {
    $clock = new PTX\Clock('09:55');
    $clock->draw();
    $clock->to_browser();
} catch(\PTX\ClockException $e) {
    echo $e->getMessage();
}

Example online

Visit my page and see it in action.


  PTX ClockExternal page  

Open in a separate window

  Files folder image Files  
File Role Description
Files folder imagecache (1 file)
Files folder imageexample (2 files, 3 directories)
Files folder imagefonts (2 directories)
Files folder imagesrc (1 directory)
Files folder imagetests (2 files)
Accessible without login Plain text file canvas.php Example Example script
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file index.php Example Example script
Accessible without login Plain text file LICENSE Lic. Auxiliary data
Accessible without login Plain text file README.md Doc. Auxiliary data

 Version Control Unique User Downloads Download Rankings  
 100%
Total:308
This week:0
All time:7,323
This week:114Up