mirror of
https://github.com/ful1e5/Bibata_Cursor.git
synced 2025-05-30 06:45:31 -04:00
💾 Save Animated Cursors frames
This commit is contained in:
parent
bf2dff2370
commit
427c53679a
1 changed files with 13 additions and 9 deletions
|
@ -17,11 +17,8 @@ export class BitmapsGenerator {
|
||||||
private readonly animatedCurs: Cursors;
|
private readonly animatedCurs: Cursors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param source `BitmapsGenerator` Class's object arguments.
|
* @param source `BitmapsGenerator` Class's object arguments.
|
||||||
*
|
|
||||||
* @param themeName name of the bitmaps directory.
|
* @param themeName name of the bitmaps directory.
|
||||||
*
|
|
||||||
* @param bitmapsDir `absolute` or `relative` path, Where cursors `.png` files generated.
|
* @param bitmapsDir `absolute` or `relative` path, Where cursors `.png` files generated.
|
||||||
*/
|
*/
|
||||||
constructor(
|
constructor(
|
||||||
|
@ -38,7 +35,6 @@ export class BitmapsGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* Create directory if it doesn't exists.
|
* Create directory if it doesn't exists.
|
||||||
*
|
*
|
||||||
* @param dirPath directory `absolute` or `relative` path.
|
* @param dirPath directory `absolute` or `relative` path.
|
||||||
|
@ -54,7 +50,6 @@ export class BitmapsGenerator {
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param browser `puppeteer` browser instance.
|
* @param browser `puppeteer` browser instance.
|
||||||
*
|
|
||||||
* @param content `.svg` file code.
|
* @param content `.svg` file code.
|
||||||
*/
|
*/
|
||||||
private async getSvgElement(
|
private async getSvgElement(
|
||||||
|
@ -74,7 +69,6 @@ export class BitmapsGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* Close all pages of `Puppeteer.Browser`.
|
* Close all pages of `Puppeteer.Browser`.
|
||||||
*
|
*
|
||||||
* @param browser `puppeteer` browser instance.
|
* @param browser `puppeteer` browser instance.
|
||||||
|
@ -85,11 +79,9 @@ export class BitmapsGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* Generate `static` cursors bitmaps.
|
* Generate `static` cursors bitmaps.
|
||||||
*
|
*
|
||||||
* @param browser `puppeteer` browser instance.
|
* @param browser `puppeteer` browser instance.
|
||||||
*
|
|
||||||
* @param spinner `Ora` instance.
|
* @param spinner `Ora` instance.
|
||||||
*/
|
*/
|
||||||
private async renderStaticCurs(browser: Browser, spinner: Ora) {
|
private async renderStaticCurs(browser: Browser, spinner: Ora) {
|
||||||
|
@ -110,12 +102,21 @@ export class BitmapsGenerator {
|
||||||
await this.closeAllPages(browser);
|
await this.closeAllPages(browser);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save animated cursors frames.
|
||||||
|
* @param frames Record of `binary` Buffer.
|
||||||
|
*/
|
||||||
|
private saveFrames(frames: Frames) {
|
||||||
|
for (let [cursor, { buffer }] of Object.entries(frames)) {
|
||||||
|
const out_path = path.resolve(this.bitmapsDir, `${cursor}.png`);
|
||||||
|
fs.writeFileSync(out_path, buffer, { encoding: "binary" });
|
||||||
|
}
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Generate `animated` cursors bitmaps.
|
* Generate `animated` cursors bitmaps.
|
||||||
*
|
*
|
||||||
* @param browser `puppeteer` browser instance.
|
* @param browser `puppeteer` browser instance.
|
||||||
*
|
|
||||||
* @param spinner `Ora` instance.
|
* @param spinner `Ora` instance.
|
||||||
*/
|
*/
|
||||||
private async renderAnimatedCurs(browser: Browser, spinner: Ora) {
|
private async renderAnimatedCurs(browser: Browser, spinner: Ora) {
|
||||||
|
@ -150,6 +151,7 @@ export class BitmapsGenerator {
|
||||||
omitBackground: true,
|
omitBackground: true,
|
||||||
encoding: "binary"
|
encoding: "binary"
|
||||||
});
|
});
|
||||||
|
|
||||||
const matched = matchImages({
|
const matched = matchImages({
|
||||||
img1Buff: frames[firstFrame].buffer,
|
img1Buff: frames[firstFrame].buffer,
|
||||||
img2Buff: newFrame
|
img2Buff: newFrame
|
||||||
|
@ -163,6 +165,8 @@ export class BitmapsGenerator {
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.saveFrames(frames);
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.closeAllPages(browser);
|
await this.closeAllPages(browser);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue