lotus / backend /canvas.ts
k-l-lambda's picture
commit lotus dist.
d605f27
raw
history blame
554 Bytes
//import {loadImage, createCanvas} from "canvas";
import {PNGStream} from "canvas";
const {loadImage, createCanvas}: any = !process.env.MOBILE_MODE ? require("canvas") : {};
const svgToPng = async (sourceURL: string|Buffer): Promise<PNGStream> => {
if (process.env.MOBILE_MODE)
return;
const image = await loadImage(sourceURL);
const canvas = createCanvas(image.width, image.height);
const ctx = canvas.getContext("2d");
ctx.drawImage(image, 0, 0, image.width, image.height);
return canvas.createPNGStream();
};
export {
svgToPng,
};