💾 Save All frames utils

This commit is contained in:
ful1e5 2020-08-29 11:34:01 +05:30
parent 27113e4e7a
commit 617f218719
2 changed files with 19 additions and 0 deletions

View file

@ -11,6 +11,7 @@ import {
animatedClip, animatedClip,
} from "./config"; } from "./config";
import { matchImages } from "./utils/matchImages"; import { matchImages } from "./utils/matchImages";
import { saveFrames } from "./utils/saveFrames";
const main = async () => { const main = async () => {
const browser = await puppeteer.launch({ const browser = await puppeteer.launch({
@ -104,6 +105,8 @@ const main = async () => {
index++; index++;
} }
saveFrames({ fileName: svg, frames });
await page.close(); await page.close();
} }

16
src/utils/saveFrames.ts Normal file
View file

@ -0,0 +1,16 @@
import fs from "fs";
import { getOutPath } from "./getOutPath";
interface SaveFramesArguments {
fileName: string;
frames: Buffer[];
}
export const saveFrames = ({ fileName, frames }: SaveFramesArguments) => {
let index = 1;
const totalFrames = Buffer.length;
for (let [frameBuffer] of Object.entries(frames)) {
const out = getOutPath(index, totalFrames, fileName);
fs.writeFileSync(out, frameBuffer);
index++;
}
};