Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions GIFEncoder.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ class AnimatedGif {
private $buffer = Array();

/**
* How many times to loop? 0 = infinite
* How many times to loop?
* 0 = infinite
* false = no loop
* @var int
*/
private $number_of_loops = 0;
Expand Down Expand Up @@ -83,7 +85,7 @@ function __construct(array $source_images, array $image_delays, $number_of_loops
$transparent_colour_green = 0;
$transparent_colour_blue = 0;

$this->number_of_loops = ( $number_of_loops > -1 ) ? $number_of_loops : 0;
$this->number_of_loops = $number_of_loops;
$this->set_transparent_colour($transparent_colour_red, $transparent_colour_green, $transparent_colour_blue);
$this->buffer_images($source_images);

Expand Down Expand Up @@ -133,14 +135,16 @@ private function buffer_images($source_images) {
* Add the gif header to the image
*/
private function addHeader() {
$cmap = 0;
$this->image = 'GIF89a';
if (ord($this->buffer [0] { 10 }) & 0x80) {
$cmap = 3 * ( 2 << ( ord($this->buffer [0] { 10 }) & 0x07 ) );
$this->image .= substr($this->buffer [0], 6, 7);
$this->image .= substr($this->buffer [0], 13, $cmap);
$this->image .= "!\377\13NETSCAPE2.0\3\1" . $this->word($this->number_of_loops) . "\0";
}
$cmap = 0;
$this->image = 'GIF89a';
if (ord($this->buffer [0] { 10 }) & 0x80) {
$cmap = 3 * ( 2 << ( ord($this->buffer [0] { 10 }) & 0x07 ) );
$this->image .= substr($this->buffer [0], 6, 7);
$this->image .= substr($this->buffer [0], 13, $cmap);
if($this->number_of_loops !== false){
$this->image .= "!\377\13NETSCAPE2.0\3\1" . $this->word($this->number_of_loops) . "\0";
}
}
}

/**
Expand Down
13 changes: 7 additions & 6 deletions gif.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@
$frames = array();
$delays = array();

//false = no loop
//0 = infinite
$loops = false;

// Your image link
$image = imagecreatefrompng('images/countdown.png');

$delay = 100;// milliseconds

$font = array(
'size' => 23, // Font size, in pts usually.
'size' => 18, // Font size, in pts usually.
'angle' => 0, // Angle of the text
'x-offset' => 7, // The larger the number the further the distance from the left hand side, 0 to align to the left.
'y-offset' => 30, // The vertical alignment, trial and error between 20 and 60.
'x-offset' => 9, // The larger the number the further the distance from the left hand side, 0 to align to the left.
'y-offset' => 28, // The vertical alignment, trial and error between 20 and 60.
'file' => __DIR__ . DIRECTORY_SEPARATOR . 'Futura.ttc', // Font path
'color' => imagecolorallocate($image, 55, 160, 130), // RGB Colour of the text
);
Expand All @@ -33,13 +36,12 @@
// Open the first source image and add the text.
$image = imagecreatefrompng('images/countdown.png');
;
$text = $interval->format('00:00:00:00');
$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 {
Expand All @@ -52,7 +54,6 @@
imagegif($image);
$frames[]=ob_get_contents();
$delays[]=$delay;
$loops = 0;
ob_end_clean();
}

Expand Down