Skip to content

Instantly share code, notes, and snippets.

@rubenarakelyan
Created October 17, 2024 09:22
Show Gist options
  • Save rubenarakelyan/a35994de769192b1ba3a92d138f5f0ff to your computer and use it in GitHub Desktop.
Save rubenarakelyan/a35994de769192b1ba3a92d138f5f0ff to your computer and use it in GitHub Desktop.
Server-push animation
#!/usr/bin/perl
use strict;
use warning;
use GD;
$images = "/path/to/images";
$header = "Content-type: multipart/x-mixed-replace; boundary=ddc072ce-3b52-4704-9fef-abf661a13d43\n";
$boundary = "\n--ddc072ce-3b52-4704-9fef-abf661a13d43\n";
$giftype = "Content-type: image/gif\n\n";
print $header;
print $boundary;
$i = 1;
while (1) {
sleep 1;
print $giftype;
open(GIFH, "< ${images}/frame${i}.gif");
$img = newFromGif GD::Image(GIFH);
close(GIFH);
print $img->gif;
print $boundary;
if ($i == 21) {
$i = 1;
} else {
$i++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment