working gif encoding