forked from thx/resvg-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dependent on deno 1.26.1 `deno run --unstable --allow-read --allow-write --allow-ffi example/index-deno.js`
- Loading branch information
Showing
3 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.