From 036ba2ec65cb85a6965443b583c37d6fb3182d40 Mon Sep 17 00:00:00 2001 From: MatheusR42 Date: Sat, 28 Jan 2017 19:02:21 -0200 Subject: [PATCH] Update Looping and letter position --- GIFEncoder.class.php | 24 ++++++++++++++---------- gif.php | 13 +++++++------ 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/GIFEncoder.class.php b/GIFEncoder.class.php index 7cac97c..40997c0 100755 --- a/GIFEncoder.class.php +++ b/GIFEncoder.class.php @@ -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; @@ -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); @@ -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"; + } + } } /** diff --git a/gif.php b/gif.php index b7d150d..0face52 100755 --- a/gif.php +++ b/gif.php @@ -11,6 +11,9 @@ $frames = array(); $delays = array(); + //false = no loop + //0 = infinite + $loops = false; // Your image link $image = imagecreatefrompng('images/countdown.png'); @@ -18,10 +21,10 @@ $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 ); @@ -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 { @@ -52,7 +54,6 @@ imagegif($image); $frames[]=ob_get_contents(); $delays[]=$delay; - $loops = 0; ob_end_clean(); }