Skip to content

Commit

Permalink
chore: add deno example
Browse files Browse the repository at this point in the history
Dependent on deno 1.26.1

`deno run --unstable --allow-read --allow-write --allow-ffi example/index-deno.js`
  • Loading branch information
yisibl committed Nov 17, 2022
1 parent 78a30d9 commit 5306113
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ parserOptions:
ecmaVersion: latest
sourceType: module

globals:
Deno: readonly

env:
browser: true
es6: true
Expand Down
31 changes: 31 additions & 0 deletions example/index-deno.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { performance } from 'https://deno.land/std@0.159.0/node/perf_hooks.ts'
import * as path from 'https://deno.land/std@0.159.0/path/mod.ts'
import { Resvg } from 'npm:@resvg/resvg-js'

const __dirname = path.dirname(path.fromFileUrl(import.meta.url))

const svg = await Deno.readFile(path.join(__dirname, './text.svg'))
const opts = {
background: 'rgba(238, 235, 230, .9)',
fitTo: {
mode: 'width',
value: 1200,
},
font: {
fontFiles: ['./example/SourceHanSerifCN-Light-subset.ttf'], // Load custom fonts.
loadSystemFonts: false, // It will be faster to disable loading system fonts.
defaultFontFamily: 'Source Han Serif CN Light',
},
logLevel: 'debug', // Default Value: error
}

const t = performance.now()
const resvg = new Resvg(svg, opts)
const pngData = resvg.render()
const pngBuffer = pngData.asPng()

console.info('Original SVG Size:', `${resvg.width} x ${resvg.height}`)
console.info('Output PNG Size :', `${pngData.width} x ${pngData.height}`)
console.info('✨ Done in', performance.now() - t, 'ms')

await Deno.writeFile(path.join(__dirname, './text-out-deno.png'), pngBuffer)
Binary file added example/text-out-deno.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5306113

Please sign in to comment.