mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-22 03:07:04 +02:00
feat: organized files
This commit is contained in:
1 parent
f2ae698438
commit
7dd3913ae8
51 files changed
+68
-68
No files matched your search
@@ -0,0 +1,42 @@
|
||||
import { readFile } from 'fs';
|
||||
import { join } from 'path';
|
||||
import satori from 'satori';
|
||||
import robotoBlackFile from '../../assets/fonts/Roboto-Black.ttf';
|
||||
import robotoBoldFile from '../../assets/fonts/Roboto-Bold.ttf';
|
||||
import robotoFile from '../../assets/fonts/Roboto.ttf';
|
||||
|
||||
const FONT_NAME = 'Roboto';
|
||||
const FONT_FILES = [robotoFile, robotoBoldFile, robotoBlackFile];
|
||||
|
||||
let roboto: Buffer;
|
||||
let robotoBold: Buffer;
|
||||
let robotoBlack: Buffer;
|
||||
|
||||
console.log('Importing fonts...');
|
||||
Promise.all(
|
||||
FONT_FILES.map(
|
||||
(file) =>
|
||||
new Promise<Buffer>((resolve, reject) => {
|
||||
const path = join(__dirname, file);
|
||||
|
||||
readFile(path, (error, data) => {
|
||||
if (error) reject(error);
|
||||
resolve(data);
|
||||
});
|
||||
}),
|
||||
),
|
||||
).then((data) => {
|
||||
[roboto, robotoBold, robotoBlack] = data;
|
||||
console.log('Fonts imported');
|
||||
});
|
||||
|
||||
export default async function jsxToSvg(jsx: JSX.Element) {
|
||||
return await satori(jsx, {
|
||||
width: 640,
|
||||
fonts: [
|
||||
{ data: roboto, name: FONT_NAME, weight: 400 },
|
||||
{ data: robotoBold, name: FONT_NAME, weight: 700 },
|
||||
{ data: robotoBlack, name: FONT_NAME, weight: 900 },
|
||||
],
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import jsxToSvg from './jsxToSvg.js';
|
||||
import svgToPng from './svgToPng.js';
|
||||
|
||||
export default async function render(jsx: JSX.Element) {
|
||||
const svg = await jsxToSvg(jsx);
|
||||
const png = svgToPng(svg);
|
||||
|
||||
return png;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import { Resvg } from "@resvg/resvg-js";
|
||||
|
||||
export default function svgToPng(svg: string) {
|
||||
return new Resvg(svg).render().asPng()
|
||||
}
|
||||
Reference in new issue
Block a user