|Classes of Patrick Van Bergen||Move Me GIF||README.md||Download|
An Animated GIF creation library in pure PHP.
This library focuses on the use of GD in the creation of animated gif images.
There are three ways to create a frame:
The library uses GD's imagegif function to generate frames quickly. But in some cases it cannot be used, and compression is done in PHP, which is much slower.
Thanks a great deal to Matthew Flickinger for writing an awesome GIF format explanation
The source code (directory "example") contains a few examples to help you on the way.
Each example shows a different animation strategy. Choose the strategy that best suits your needs. Combinations of the strategies are also possible, since all settings are done on the frame level.
The Horse example shows how to animate a series of same-sized images.
The horse image was taken from Wikipedia
In this example we find Moki running in the mountains.
Frame 1 shows a background JPEG image. The following 46 frames show 10 different poses of Moki on different horizontal positions. These are transparent GIF images that are drawn and erased per frame.
The strategy here is to start with a background image and use "restore to previous frame" to paint the pictures of the dog on top of it. For each frame of the dogs animation, the GIF renderer draws the image (with transparent background), waits for the duration of the frame, and then puts the image back into the state where it was before the image was drawn. This way, the background image remains and is ready to receive the next image of the dog.
This strategy helps keep the GIF image small, since the background does not need to be stored for every frame. But is also has an important drawback: in a looping, when all frames have drawn, a completely empty background image will be drawn. If the dog would be on a visible position at that time, it would disappear for an instance.
The elaborate PONG example shows how you can keep the filesize small while creating a large number of frames, by the use of
In this example a complete frame takes 5kB in the compressed GIF format. The animation takes 270 steps and would take over a MB if unclipped frames were used. Using the two techniques, the image just takes 179 kB.
The strategy here is to draw each frame completely (with GD lib), but to create frames only of the areas of the image that have changed.
Another PHP animated GIF library was written by László Zsidi and can be found at phpclasses.org
The standard GIF library is written in C and can be found here
The GIF 89a specification is located here