I have created a GIF LiveTimer and the code is below.
Where default timezone is 'Australia/Melbourne' which is hardcoded in gif.php file.
Running Timer GIF Example is below. Where I want dynamic timezone. http://gifcountdowntimergenrator.atwebpages.com/module/gif.php?time=2018-09-06+17:58:28
gif.php
<?php
date_default_timezone_set('Australia/Melbourne');
function tz_list() {
$zones_array = array();
$timestamp = time();
foreach(timezone_identifiers_list() as $key => $zone) {
date_default_timezone_set($zone);
$zones_array[$key]['zone'] = $zone;
$zones_array[$key]['diff_from_GMT'] = 'UTC/GMT ' . date('P', $timestamp);
}
return $zones_array;
}
include 'GIFEncoder.class.php';
include 'php52-fix.php';
$time = $_GET['time'];
$future_date = new DateTime(date('r',strtotime($time)));
$time_now = time();
$now = new DateTime(date('r', $time_now));
$frames = array();
$delays = array();
$image = imagecreatefrompng('../images/timer.png');
$delay = 100; // milliseconds
$font = array(
'size' => 50, // Font size, in pts usually.
'angle' => 0, // Angle of the text
'x-offset' => 23, // The larger the number the further the distance from the left hand side, 0 to align to the left.
'y-offset' => 70, // The vertical alignment, trial and error between 20 and 60.
'file' => __DIR__ . DIRECTORY_SEPARATOR . '../fonts/arial.ttf', // Font path
'color' => imagecolorallocate($image, 0, 36, 150), // RGB Colour of the text
);
for($i = 0; $i <= 60; $i++){
$interval = date_diff($future_date, $now);
if($future_date < $now){
// Open the first source image and add the text.
$image = imagecreatefrompng('../images/timer.png');;
$text = $interval->format('00:00:00:00');
imagettftext ($image , $font['size'] , $font['angle'] , $font['x-offset'] , $font['y-offset'] , $font['color'] , $font['file'], $text );
ob_start();
imagegif($image);
$frames[]=ob_get_contents();
$delays[]=$delay;
$loops = 1;
ob_end_clean();
break;
} else {
// Open the first source image and add the text.
$image = imagecreatefrompng('../images/timer.png');;
$text = $interval->format('%a:%H:%I:%S');
// %a is weird in that it doesn’t give you a two digit number
// check if it starts with a single digit 0-9
// and prepend a 0 if it does
if(preg_match('/^[0-9]\:/', $text)){
$text = '0'.$text;
}
imagettftext ($image , $font['size'] , $font['angle'] , $font['x-offset'] , $font['y-offset'] , $font['color'] , $font['file'], $text );
ob_start();
imagegif($image);
$frames[]=ob_get_contents();
$delays[]=$delay;
$loops = 0;
ob_end_clean();
}
$now->modify('+1 second');
}
//expire this image instantly
header( 'Expires: Sat, 26 Jul 1997 05:00:00 GMT' );
header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' );
header( 'Cache-Control: no-store, no-cache, must-revalidate' );
header( 'Cache-Control: post-check=0, pre-check=0', false );
header( 'Pragma: no-cache' );
$gif = new AnimatedGif($frames,$delays,$loops);
$gif->display();
?>
I want this timezone to be updated dynamically whenever I select timezone through UI, screenshot is below
timer.php
I am below code to generate Timezones
<?php
/**
* Timezones list with GMT offset
*
* @return array
* @link http://stackoverflow.com/a/9328760
*/
function tz_list() {
$zones_array = array();
$timestamp = time();
foreach(timezone_identifiers_list() as $key => $zone) {
date_default_timezone_set($zone);
$zones_array[$key]['zone'] = $zone;
$zones_array[$key]['diff_from_GMT'] = 'UTC/GMT ' . date('P', $timestamp);
}
return $zones_array;
}
?>
<select>
<option value="0">Please, select timezone</option>
<?php foreach(tz_list() as $t) { ?>
<option value="<?php print $t['zone'] ?>">
<?php print $t['diff_from_GMT'] . ' - ' . $t['zone'] ?>
</option>
<?php } ?>
</select>
But the problem is that if I am using POST method then GIF PHP is not working then and image is not generating.
Is there any way to get timezone in dynamically which would not effect the result
gif.php