-
Notifications
You must be signed in to change notification settings - Fork 0
/
bc-animate-gif.pl
executable file
·67 lines (49 loc) · 1.41 KB
/
bc-animate-gif.pl
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
#!/bin/perl
# attempt to display "animated PNG" (really MIME multipart) that may
# one day display bandwidth speed
# http://test.barrycarter.info/bc-animate-gif.pl
push(@INC, "/usr/local/lib");
require "bclib.pl";
use GD;
use Time::HiRes;
# avoid caching
select(STDOUT);
$|=1;
# TODO: count time to the millisecond
$t0 = time();
# MIME boundary
$boundary="---xyz---";
countprint("Content-type: multipart/x-mixed-replace;boundary=$boundary\n\n");
# the boundry for the first image
countprint("$boundary\n");
# this loop goes forever
for (;;) {
# header for this specific image
countprint("Content-type: image/png\n\n");
# testing by just printing increasing numbers
$n++;
# create the image (following "perldoc GD" here) w/ transparent bg
$im = new GD::Image(800,30);
$white = $im->colorAllocate(255,255,255);
$black = $im->colorAllocate(0,0,0);
$im->transparent($white);
# time so far
$t = time()-$t0;
# rate
$rate = $bytes/($t||1);
# and write my string
$im->string(GD::gdGiantFont,0,0,"I have sent $bytes bytes in $t seconds. That's $rate bytes per second",$black);
countprint($im->png);
# end boundary
countprint("\n$boundary\n");
# safety check (for now)
Time::HiRes::sleep(0.001);
}
# in theory, could end entire MIMEtype here, but since loop above is
# infinite, no need
# count bytes as I print them
sub countprint {
my($str) = @_;
$bytes+= length($str);
print $str;
}