src/Intervention/Gif/Decoder.php
private function decodeExtension(Decoded $gif)
    {
        switch ($this->getNextBytes(1)) {

            case self::GRAPHICS_CONTROL_EXTENSION_MARKER:
                $gif->addGraphicsControlExtension($this->getNextBytes(6));
                break;

            case self::APPLICATION_EXTENSION_MARKER:
                $application_block_size = $this->getNextBytes(1);
                $application_block_size = unpack('C', $application_block_size)[1];
                $application_block = $this->getNextBytes($application_block_size);

                // only save netscape application extension
                if ($application_block == self::NETSCAPE_EXTENSION_MARKER) {

                    $data_block_size = $this->getNextBytes(1);
                    $data_block_size = unpack('C', $data_block_size)[1];
                    $data_block = $this->getNextBytes($data_block_size);

                    $extension = "\x0B";
                    $extension .= self::NETSCAPE_EXTENSION_MARKER;
                    $extension .= "\x03";
                    $extension .= $data_block;
                    $extension .= "\x00";
                    $gif->setNetscapeExtension($extension);

                } elseif ($application_block == self::XMP_EXTENSION_MARKER) {
                        
                    do {
                        // skip xmp data for now
                        $byte = $this->getNextBytes(1);
                    } while ($byte != "\x00");

                } else {
                    
                    $data_block_size = $this->getNextBytes(1);
                    $data_block_size = unpack('C', $data_block_size)[1];
                    $data_block = $this->getNextBytes($data_block_size);

                }

                // subblock
                $this->getNextBytes(1);

                break;

            case self::PLAINTEXT_EXTENSION_MARKER:
                $blocksize = $this->getNextBytes(1);
                $blocksize = unpack('C', $blocksize)[1];
                $gif->setPlaintextExtension($this->getNextBytes($blocksize));
                $this->getNextBytes(1); // null byte
                break;

            case self::COMMENT_EXTENSION_MARKER:
                $blocksize = $this->getNextBytes(1);
                $blocksize = unpack('C', $blocksize);
                $gif->setCommentExtension($this->getNextBytes($blocksize));
                $this->getNextBytes(1); // null byte
                break;
            
            default:
                # code...
                break;
        }
    }
private function decodeExtension(Decoded $gif)
    {
        switch ($this->getNextBytes(1)) {

            case self::GRAPHICS_CONTROL_EXTENSION_MARKER:
                $gif->addGraphicsControlExtension($this->getNextBytes(6));
                break;

            case self::APPLICATION_EXTENSION_MARKER:
                $application_block_size = $this->getNextBytes(1);
                $application_block_size = unpack('C', $application_block_size)[1];
                $application_block = $this->getNextBytes($application_block_size);

                // only save netscape application extension
                if ($application_block == self::NETSCAPE_EXTENSION_MARKER) {

                    $data_block_size = $this->getNextBytes(1);
                    $data_block_size = unpack('C', $data_block_size)[1];
                    $data_block = $this->getNextBytes($data_block_size);

                    $extension = "\x0B";
                    $extension .= self::NETSCAPE_EXTENSION_MARKER;
                    $extension .= "\x03";
                    $extension .= $data_block;
                    $extension .= "\x00";
                    $gif->setNetscapeExtension($extension);

                } elseif ($application_block == self::XMP_EXTENSION_MARKER) {
                        
                    do {
                        // skip xmp data for now
                        $byte = $this->getNextBytes(1);
                    } while ($byte != "\x00");

                } else {
                    
                    $data_block_size = $this->getNextBytes(1);
                    $data_block_size = unpack('C', $data_block_size)[1];
                    $data_block = $this->getNextBytes($data_block_size);

                }

                // subblock
                $this->getNextBytes(1);

                break;

            case self::PLAINTEXT_EXTENSION_MARKER:
                $blocksize = $this->getNextBytes(1);
                $blocksize = unpack('C', $blocksize)[1];
                $gif->setPlaintextExtension($this->getNextBytes($blocksize));
                $this->getNextBytes(1); // null byte
                break;

            case self::COMMENT_EXTENSION_MARKER:
                $blocksize = $this->getNextBytes(1);
                $blocksize = unpack('C', $blocksize);
                $gif->setCommentExtension($this->getNextBytes($blocksize));
                $this->getNextBytes(1); // null byte
                break;
            
            default:
                # code...
                break;
        }
    }
Decode extension in image stream

@param  Decoded $gif
@return void