It's not possible using the standard GD functions that come pre-packed with PHP.
There is a class on phpclasses.org for this. I have never used it myself, but it's used by a lot of other packages.
Alternatively, if you have access to ImageMagick from PHP, using either the MagickWand library or the command line, use it. With ImageMagick, it's no problem.
ImageMagick v6 Animation basics (from the IM manual)
Creating an Animated GIF image