<?php
header ('Content-type:image/gif');
error_reporting(-1);

include('GIFEncoder.class.php');
$text = "Hello World";

$image = @imagecreate(100, 100)
    or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($image, 0, 0, 0);
$text_color = imagecolorallocate($image, 233, 14, 91);
$text_color = imagecolorallocate($image, 200, 200, 200);
$red = imagecolorallocate($image, 255, 0, 0);
$amt = 150; 
$y = 50;
$x = 50;
for ($i = 0; $i < $amt; $i++)
{
    $c = rand() % 255;    
    $n1 = rand() % 2;
    $n2 = rand() % 2;
    $n3 = rand() % 2;
    $n4 = rand() % 2;

    if($n1 == 0)
        $x+=2;
    else if($n2 == 1)
        $x-=2;
    if($n3 == 0)
        $y-=2;
    else if($n4 == 0)
        $y+=2;

    $i++;
    imagesetpixel($image, $x, $y,$red );
    imagesetpixel($image, $x+1, $y,$red );
    imagesetpixel($image, $x, $y+1,$red );
    imagesetpixel($image, $x+1, $y+1,$red );

//    imagesetpixel($image,$i,$i,$red);
    ob_start();
    imagegif($image);
    $frames[]=ob_get_contents();
    $framed[]=14;

    // Delay in the animation.
    ob_end_clean();
}



// Generate GIF from the $image
// We want to put the binary GIF data into an array to be used later,
//  so we use the output buffer.
ob_start();
imagegif($image);
$frames[]=ob_get_contents();
$framed[]=40;

ob_end_clean();

// Generate the animated gif and output to screen.
$gif = new GIFEncoder($frames,$framed,0,2,0,0,0,'bin');
echo $gif->GetAnimation();
//$fp = fopen('animegif.gif', 'w');
//fwrite($fp, $gif->GetAnimation());
//fclose($fp);
?>