-
Notifications
You must be signed in to change notification settings - Fork 14
/
gif.php
70 lines (62 loc) · 2.03 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
<?php
date_default_timezone_set('Australia/Melbourne');
include 'GIFEncoder.class.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('countdown.png');
$delay = 100; // milliseconds
$font = array(
'size'=>40,
'angle'=>0,
'x-offset'=>10,
'y-offset'=>70,
'file'=>'DIGITALDREAM.ttf',
'color'=>imagecolorallocate($image, 255, 255, 255),
);
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('countdown.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('countdown.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();
?>