public function addFrame($frame, $delay = 0)
{
$data = '';
if (null === $this->initialFrame) {
$this->initialFrame = $frame;
$data .= $this->writeHeader($frame);
}
$sourceHeader = substr($frame, 0, 6);
if (!in_array($sourceHeader, array('GIF87a', 'GIF89a'))) {
throw new \InvalidArgumentException('Input frame must be a GIF');
}
$i = 13 + 3 * (2 << (ord($frame[10]) & 0x7));
while (true) {
$sectionType = $frame[$i];
if ('!' === $sectionType && 'NETSCAPE' === substr($frame, $i + 3, 8)) {
throw new \InvalidArgumentException('Input frame must not be animated');
}
if (';' === $sectionType) {
break;
}
$i++;
}
$data .= $this->encodeFrame($frame, $delay);
return $data;
}