Please keep the discussion here friendly, if you want help.


import { Resvg, ResvgRenderOptions, initWasm } from '@resvg/resvg-wasm';
import wasmModule from '@resvg/resvg-wasm/index_bg.wasm';
export const generateImage = async (text: string) => {
console.log(text, "this is the text");
const svg = ;
try {
await initWasm(wasmModule);
} catch (error) {
console.error('Resvg wasm not initialized');
throw error;
}
const opts: ResvgRenderOptions = {
background: "white", // Optional: set background color
fitTo: {
mode: "width",
value: 600, // Adjust based on your needs
},
font: {
loadSystemFonts: true, // Disable system fonts if you're using custom fonts
},
};
const resvg = new Resvg(svg, opts);
console.log(resvg, "this is the resvg");
const pngData = resvg.render();
const pngBuffer = pngData.asPng();
return pngBuffer;
};fontBuffer is a raw ttffs of course, but worth a try)
import { DurableObject } from "cloudflare:workers";Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. Received protocol 'cloudflare:'@cloudflare/workers work?
Please keep the discussion here friendly, if you want help.import { Resvg, ResvgRenderOptions, initWasm } from '@resvg/resvg-wasm';
import wasmModule from '@resvg/resvg-wasm/index_bg.wasm';
export const generateImage = async (text: string) => {
console.log(text, "this is the text");
const svg = ;
try {
await initWasm(wasmModule);
} catch (error) {
console.error('Resvg wasm not initialized');
throw error;
}
const opts: ResvgRenderOptions = {
background: "white", // Optional: set background color
fitTo: {
mode: "width",
value: 600, // Adjust based on your needs
},
font: {
loadSystemFonts: true, // Disable system fonts if you're using custom fonts
},
};
const resvg = new Resvg(svg, opts);
console.log(resvg, "this is the resvg");
const pngData = resvg.render();
const pngBuffer = pngData.asPng();
return pngBuffer;
};fontBufferttfimport { DurableObject } from "cloudflare:workers";Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. Received protocol 'cloudflare:'@cloudflare/workersfont: {
fontsBuffers: [fontBuffer], //
},