trismi
trismi

Reputation: 780

PHP Imagick: set a gif animation loop to none?

I've successfully generated an animated gif from a directory of images. I can't figure out how to keep it from looping, though, it just keeps going and going. I think I found the setting in ImageMagick, but I don't see a corresponding way to set it in the Imagick PHP library. Does anyone know what it is?

Upvotes: 1

Views: 2056

Answers (1)

Orbling
Orbling

Reputation: 20612

Took me a while to find it, as missed it going through the IMagick documentation. But you can set the loop for animated gifs using IMagick.

When I was looking at the code that writes out the Netscape Loop extension in the proper ImageMagick code, it uses an internal variable for the image called iterations despite, using -loop on the command line. It uses iterations internally the whole time and that is followed through in to the IMagick code.


From ImageMagick code: coders/gif.c

1689        if ((GetPreviousImageInList(image) == (Image *) NULL) &&
1690                (GetNextImageInList(image) != (Image *) NULL) &&
1691                (image->iterations != 1))
1692              {
1693                /*
1694                  Write Netscape Loop extension.
1695                */
1696                (void) LogMagickEvent(CoderEvent,GetMagickModule(),
1697                   "  Writing GIF Extension %s","NETSCAPE2.0");
1698                (void) WriteBlobByte(image,(unsigned char) 0x21);
1699                (void) WriteBlobByte(image,(unsigned char) 0xff);
1700                (void) WriteBlobByte(image,(unsigned char) 0x0b);
1701                (void) WriteBlob(image,11,(unsigned char *) "NETSCAPE2.0");
1702                (void) WriteBlobByte(image,(unsigned char) 0x03);
1703                (void) WriteBlobByte(image,(unsigned char) 0x01);
1704                (void) WriteBlobLSBShort(image,(unsigned short) image->iterations);
1705                (void) WriteBlobByte(image,(unsigned char) 0x00);
1706              }

See the documentation: IMagick::setImageIterations( int $iterations )

Setting $iterations = 0 makes it loop infinitely.

The delay between frames is set using the tick format I believe, using:

Upvotes: 4

Related Questions