The optimization algorithm is only applicable to the image of mode="P" or "L".

(This issue was previously addressed in #991 )

The optimization algorithm used in getheader() assumes the image data is 8bpp and therefore it cannot be applied to the bi-level'ed image which is also supported by the GIF plugin.  It is of course possible to support optimization for such images, but it would need a specific hack around the unpacker and I don't think it is appropriate.