-
Notifications
You must be signed in to change notification settings - Fork 149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to create non loop GIF image #4
Comments
If you only want the animation to show once, set loop to 1. The README file says that setting loop to zero will give you an infinite loop. |
<?
error_reporting(0);
set_time_limit(0);
define('LEFT', 130);
define('WIDTH', 360);
define('HEIGHT', 110);
define('SPEED', 100);
define('LOOP', 1); // Not working yet
global $frames, $durations;
$files = array(
'http://img.page2images.com/ccimages/28/2c/mGOIqfym1vkiYiSN.png',
'http://img.page2images.com/ccimages/bf/25/htg5zcWBGFTzrgVY.png',
'http://img.page2images.com/ccimages/38/3a/egKwE9Egqt7xg5Yx.png',
'http://img.page2images.com/ccimages/c5/62/ntnzrgKKU1p5ZGmb.png',
'http://img.page2images.com/ccimages/3c/39/nV0HB0uz8THOL0IZ.png'
);
foreach ($files as $file) {
$img = imagecreatetruecolor(WIDTH, HEIGHT);
$im = imagecreatefrompng($file);
$ims = getimagesize($file);
imagecopy($img, $im, 0, 0, LEFT, 0, WIDTH, HEIGHT);
ob_start();
imagegif($img);
$frames[] = ob_get_contents();
$durations[] = SPEED;
ob_end_clean();
}
include_once 'GifCreator.php';
$gc = new GifCreator();
$gc->create($frames, $durations, LOOP);
header('Content-type: image/gif');
echo $gc->getGif(); |
Output you can see at http://indapublic.ru/gif/ |
Your gif plays only once in Firefox and Opera. Which browser do you use when the gif loops? |
Opera 12.16 - Once Safari, MacOS Version 7.0.3 (9537.75.14) - Twice |
I think the patch below will fix the problem with "animate only once" and seems to work in both Firefox and Chrome. diff --git a/src/GifCreator/GifCreator.php b/src/GifCreator/GifCreator.php
index 2bc4a1f..9b128ac 100644
--- a/src/GifCreator/GifCreator.php
+++ b/src/GifCreator/GifCreator.php
@@ -193,7 +193,9 @@ class GifCreator
$this->gif .= substr($this->frameSources[0], 6, 7);
$this->gif .= substr($this->frameSources[0], 13, $cmap);
- $this->gif .= "!\377\13NETSCAPE2.0\3\1".$this->encodeAsciiToChar($t
+ if ($this->loop != 1) {
+ $this->gif .= "!\377\13NETSCAPE2.0\3\1".$this->encodeAsciiToChar(
+ }
}
}
The main problem is that different browsers seem to have their own idea on how to interpret the loop counter so it's impossible to fix this in GifCreator. It seems possible to work well for loop values 0 (infinity) and 1 (play once), but for other values there will be differences between browsers.
|
Thank you, it work |
I found a solution, use a forked class with this fix: |
or
But image still looped.
The text was updated successfully, but these errors were encountered: