-
Notifications
You must be signed in to change notification settings - Fork 0
/
gif.php
80 lines (73 loc) · 2.29 KB
/
gif.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
date_default_timezone_set('Australia/NSW');
require_once 'GIFEncoder.class.php';
/*
phpinfo();
error_reporting(E_ALL); ini_set('display_errors', 1);
*/
$time = $_GET['time'];
$future_date = new DateTime(date('r',strtotime($time)));
$time_now = time();
$now = new DateTime(date('r', $time_now));
$noSeconds = false;
if(isset($_GET['noseconds']))
$noSeconds = true;
$frames = array();
$delays = array();
if($noSeconds)
$imgFile = "img/countdown-bg-noseconds.png";
else
$imgFile = "img/countdown-bg-white2.png";
$image = imagecreatefrompng($imgFile);
$delay = 100; // milliseconds
$font = array(
'size'=>42,
'angle'=>0,
'x-offset'=>15,
'y-offset'=>70,
//'file'=>'fonts/DIGITALDREAM.ttf',
'file'=>'fonts/Gotham-Medium.ttf',
'color'=>imagecolorallocate($image, 0, 0, 0),
);
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($imgFile);
$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($imgFile);
$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();