/** * @param string $dstPath * @param int $frameCount * @param LogicalScreenDescriptor $lsd * @param AbstractExtensionBlock $aeb * * @throws Exception */ private static function writeFrame($dstPath, &$frameCount, $lsd, $aeb) { $frameCount++; if ($dstPath !== null) { $dstFileName = $dstPath . str_pad(strval($frameCount), 3, "0", STR_PAD_LEFT) . ".gif"; $fhW = new FileHandler(); $fhW->openFile($dstFileName, true); $fhW->writeData("GIF89a"); $lsd->encodeToFile($fhW); $aeb->encodeToFile($fhW); $fhW->writeData(";"); $fhW->closeFile(); } }
/** * @param string $file * * @return array with "width" and "height" of the gif file. * @throws Exception */ public static function getSize($file) { $fh = new FileHandler(); try { $fh->openFile($file); } catch (Exception $e) { throw $e; } $header = new Header($fh); if ($header->signature !== "GIF" && $header->version !== "87a" && $header->version !== "89a") { $fh->closeFile(); throw new Exception("Not a gif file."); } $size = array("width" => $fh->readUint16(), "height" => $fh->readUint16()); $fh->closeFile(); return $size; }
/** * @param $ratio * @param LogicalScreenDescriptor $lsd * * @throws Exception */ public function resize($ratio, $lsd) { $scrLp = $this->screenLeftPos; $scrTp = $this->screenTopPos; $tFileS = tempnam("BewareOfGeeksBearingGifs", "grS"); $tFileD = tempnam("BewareOfGeeksBearingGifs", "grD"); $fhT = new FileHandler(); $fhT->openFile($tFileS, true); $fhT->writeData($this->generateGif($lsd)); $fhT->closeFile(); ImageHandler::resizeGif($tFileS, $tFileD, $ratio, true); $fhT->openFile($tFileD, false); new Header($fhT); $nLsd = new LogicalScreenDescriptor($fhT); $nId = self::getFirstImageDescriptor($fhT, $this->parentGCE); $fhT->closeFile(); unset($tFileD); unset($tFileS); $this->screenLeftPos = (int) round($scrLp * $ratio); $this->screenTopPos = (int) round($scrTp * $ratio); $this->screenWidth = $nId->screenWidth; $this->screenHeight = $nId->screenHeight; $this->reserved = $nId->reserved; $this->interlaceFlag = $nId->interlaceFlag; $this->sortFlag = $nLsd->sortFlag; $this->colorTableFlag = $nLsd->colorTableFlag; $this->colorTableSize = $nLsd->colorTableSize; $this->colorTable = $nLsd->colorTable; $this->lzwMinCodeSize = $nId->lzwMinCodeSize; $this->dataSubBlocks = $nId->dataSubBlocks; }