Copied over GIFEncoder from gifsockets-server#f385006
Taking notes for self