protected function parseSizeForWebp()
{
$vp8 = substr($this->stream->read(16), 12, 4);
$len = unpack("V", $this->stream->read(4));
switch (trim($vp8)) {
case 'VP8':
$this->stream->read(6);
$width = current(unpack("v", $this->stream->read(2)));
$height = current(unpack("v", $this->stream->read(2)));
return [$width & 0x3fff, $height & 0x3fff];
case 'VP8L':
$this->stream->read(1);
$b1 = $this->getByte();
$b2 = $this->getByte();
$b3 = $this->getByte();
$b4 = $this->getByte();
$width = 1 + (($b2 & 0x3f) << 8 | $b1);
$height = 1 + (($b4 & 0xf) << 10 | $b3 << 2 | ($b2 & 0xc0) >> 6);
return [$width, $height];
case 'VP8X':
$flags = current(unpack("C", $this->stream->read(4)));
$b1 = $this->getByte();
$b2 = $this->getByte();
$b3 = $this->getByte();
$b4 = $this->getByte();
$b5 = $this->getByte();
$b6 = $this->getByte();
$width = 1 + $b1 + ($b2 << 8) + ($b3 << 16);
$height = 1 + $b4 + ($b5 << 8) + ($b6 << 16);
return [$width, $height];
default:
return null;
}
}