public function encode()
    {
        // create gif
        $encoded = $this->buildLogicalScreenDescriptor();

        if ($this->hasGlobalColorTable()) {
            $encoded .= $this->getGlobalColorTable();
        }

        // netscape extension
        if ($this->isAnimated() && $this->doesLoop()) {
            $encoded .= $this->buildNetscapeExtension();
        }

        // add frame(s)
        foreach ($this->frames as $frame) {
            $encoded .= $this->buildFrame($frame);
        }
        
        // EOF
        $encoded .= "\x3B";

        return $encoded;
    }