/koishi-plugin-resvg

A high-performance SVG renderer service | 高性能 svg 渲染服务

Primary LanguageTypeScript

koishi-plugin-resvg

npm

resvg service

example

import { Context } from 'koishi'
import { exit } from 'process'
import Resvg from 'koishi-plugin-resvg'
import { resolve } from 'path';
import { writeFileSync } from 'fs';

const app = new Context()

app.plugin(Resvg);

(async () => {
  await app.start()

  const svg = await app.resvg.renderAsync(`<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100">
    <rect x="10" y="10" width="80" height="80" fill="orange" />
  </svg>`)
  writeFileSync(resolve(__dirname, '0.jpg'), svg.asPng())

  const resvg = app.resvg.newResvg(`<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100">
    <rect x="10" y="10" width="80" height="80" fill="orange" />
  </svg>`)
  let svg2 = resvg.render()
  writeFileSync(resolve(__dirname, '1.jpg'), svg2.asPng())
  console.log(resvg.width, resvg.height)
  exit()
})()

Support matrix

Node.js 12 Node.js 14 Node.js 16 Node.js 18 Node.js 20 npm
Windows x64 npm version
Windows x32 npm version
Windows arm64 npm version
macOS x64 npm version
macOS arm64(M1) npm version
Linux x64 gnu npm version
Linux x64 musl npm version
Linux arm gnu npm version
Linux arm64 gnu npm version
Linux arm64 musl npm version
Android arm64 npm version
Android armv7 npm version