🎥 Render animated Cursors

This commit is contained in:
ful1e5 2020-08-29 18:06:38 +05:30
parent 0dba4cdd9c
commit 4cd1397c15

View file

@ -11,7 +11,8 @@ import {
animatedClip, animatedClip,
} from "./config"; } from "./config";
import { matchImages } from "./utils/matchImages"; import { matchImages } from "./utils/matchImages";
import { saveFrames } from "./utils/saveFrames"; import { saveFrames, Frames } from "./utils/saveFrames";
import { getKeyName } from "./utils/getKeyName";
const main = async () => { const main = async () => {
const browser = await puppeteer.launch({ const browser = await puppeteer.launch({
@ -78,16 +79,18 @@ const main = async () => {
// Render Config // Render Config
let index = 1; let index = 1;
let breakLoop = false; let breakLoop = false;
const frames: Buffer[] = []; const frames: Frames = {};
const firstKey = getKeyName(index, svg);
console.log(firstKey);
// 1st Frame // 1st Frame
frames.push( frames[firstKey] = {
await svgElement.screenshot({ buffer: await svgElement.screenshot({
omitBackground: true, omitBackground: true,
clip: animatedClip, clip: animatedClip,
encoding: "binary", encoding: "binary",
}) }),
); };
// Pushing frames until it match to 1st frame // Pushing frames until it match to 1st frame
index++; index++;
@ -97,15 +100,22 @@ const main = async () => {
clip: animatedClip, clip: animatedClip,
encoding: "binary", encoding: "binary",
}); });
const diff = matchImages(frames[0], newFrame); const key = getKeyName(index, svg);
console.log(diff, "frames", 1, "--", index); console.log(key);
if (diff < 3000) { const diff = matchImages({
img1Buff: frames[firstKey].buffer,
img2Buff: newFrame,
});
if (!(diff < 3000)) {
frames[key] = { buffer: newFrame };
} else {
breakLoop = true; breakLoop = true;
} }
index++; index++;
} }
saveFrames({ fileName: svg, frames }); saveFrames(frames);
await page.close(); await page.close();
} }