An optimized version of the GIFDecoder class (from http://www.phpclasses.org/package/3234-PHP-Split-GIF-animations-into-multiple-images.html)