コード例 #1
0
ファイル: ResizeGif.php プロジェクト: grandt/phpresizegif
 /**
  * Resize the gif by a ratio. The height and width will be scaled in proportion, maintaining the aspect ratio.
  * Example: A ratio of 0.5 will half the size, a ratio of 2 will double it.
  *
  * @param string $srcFile
  * @param string $dstFile the destination file. This will get overwritten if it already exists.
  * @param float  $ratio
  *
  * @throws Exception
  */
 public static function ResizeByRatio($srcFile, $dstFile, $ratio)
 {
     $fh = new FileHandler();
     $fhW = new FileHandler();
     try {
         $fh->openFile($srcFile);
     } 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.");
     }
     try {
         if (is_file($dstFile)) {
             unlink($dstFile);
         }
         $fhW->openFile($dstFile, true);
     } catch (Exception $e) {
         throw $e;
     }
     $fhW->writeData("GIF89a");
     $lsd = new LogicalScreenDescriptor($fh);
     $lsd->resize($ratio);
     $lsd->encodeToFile($fhW);
     self::processGifStream($fh, $fhW, $ratio, $lsd);
     $fh->closeFile();
     $fhW->closeFile();
 }
コード例 #2
0
ファイル: ExtractGif.php プロジェクト: grandt/phpresizegif
 /**
  * @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();
     }
 }