I don't want to use any software, external library (like ImageMagick)
Well, good luck with that, because 90% of the functionality the Zend Engine exports to the PHP runtime comes from libraries.
If you have any idea, I'm listening you ^^ !
Parse the binary data in the GIF format. You could use unpack(), among other things.