@resvg/resvg-js
Advanced tools
Comparing version 2.1.0 to 2.2.0
@@ -90,2 +90,5 @@ /// <reference types="node" /> | ||
/** Get the RGBA pixels of the image */ | ||
get pixels(): Buffer | ||
/** Get the PNG width */ | ||
@@ -92,0 +95,0 @@ get width(): number |
@@ -46,2 +46,4 @@ /* tslint:disable */ | ||
asPng(): Buffer | ||
/** Get the RGBA pixels of the image */ | ||
get pixels(): Buffer | ||
/** Get the PNG width */ | ||
@@ -48,0 +50,0 @@ get width(): number |
{ | ||
"name": "@resvg/resvg-js", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "A high-performance SVG renderer and toolkit, powered by Rust based resvg and napi-rs", | ||
@@ -52,3 +52,3 @@ "main": "index.js", | ||
"bench": "node -r @swc-node/register benchmark/bench.ts", | ||
"bundle": "run-p bundle:*", | ||
"bundle": "run-p 'bundle:*'", | ||
"bundle:js": "node bundle.js", | ||
@@ -81,3 +81,3 @@ "bundle:dts": "dts-bundle-generator --external-types -o wasm/index.d.ts wasm-binding.ts", | ||
"@types/node": "^18.0.0", | ||
"@types/sharp": "^0.30.4", | ||
"@types/sharp": "^0.31.0", | ||
"@typescript-eslint/eslint-plugin": "^5.30.3", | ||
@@ -89,3 +89,3 @@ "@typescript-eslint/parser": "^5.30.3", | ||
"dts-bundle-generator": "^6.12.0", | ||
"esbuild": "^0.14.48", | ||
"esbuild": "^0.15.0", | ||
"eslint": "^8.19.0", | ||
@@ -95,10 +95,10 @@ "eslint-config-prettier": "^8.5.0", | ||
"eslint-plugin-prettier": "^4.2.1", | ||
"eslint-plugin-sonarjs": "^0.13.0", | ||
"eslint-plugin-sonarjs": "^0.16.0", | ||
"husky": "^7.0.4", | ||
"jimp-compact": "^0.16.1-2", | ||
"lint-staged": "^12.5.0", | ||
"node-fetch": "2.x", | ||
"npm-run-all": "^4.1.5", | ||
"node-fetch": "2.x", | ||
"prettier": "^2.7.1", | ||
"sharp": "^0.30.7", | ||
"sharp": "^0.31.0", | ||
"typescript": "^4.7.4" | ||
@@ -144,16 +144,17 @@ }, | ||
}, | ||
"packageManager": "yarn@3.2.4", | ||
"optionalDependencies": { | ||
"@resvg/resvg-js-win32-x64-msvc": "2.1.0", | ||
"@resvg/resvg-js-darwin-x64": "2.1.0", | ||
"@resvg/resvg-js-linux-x64-gnu": "2.1.0", | ||
"@resvg/resvg-js-linux-x64-musl": "2.1.0", | ||
"@resvg/resvg-js-linux-arm64-gnu": "2.1.0", | ||
"@resvg/resvg-js-win32-ia32-msvc": "2.1.0", | ||
"@resvg/resvg-js-linux-arm-gnueabihf": "2.1.0", | ||
"@resvg/resvg-js-darwin-arm64": "2.1.0", | ||
"@resvg/resvg-js-android-arm64": "2.1.0", | ||
"@resvg/resvg-js-android-arm-eabi": "2.1.0", | ||
"@resvg/resvg-js-linux-arm64-musl": "2.1.0", | ||
"@resvg/resvg-js-win32-arm64-msvc": "2.1.0" | ||
"@resvg/resvg-js-win32-x64-msvc": "2.2.0", | ||
"@resvg/resvg-js-darwin-x64": "2.2.0", | ||
"@resvg/resvg-js-linux-x64-gnu": "2.2.0", | ||
"@resvg/resvg-js-linux-x64-musl": "2.2.0", | ||
"@resvg/resvg-js-linux-arm64-gnu": "2.2.0", | ||
"@resvg/resvg-js-win32-ia32-msvc": "2.2.0", | ||
"@resvg/resvg-js-linux-arm-gnueabihf": "2.2.0", | ||
"@resvg/resvg-js-darwin-arm64": "2.2.0", | ||
"@resvg/resvg-js-android-arm64": "2.2.0", | ||
"@resvg/resvg-js-android-arm-eabi": "2.2.0", | ||
"@resvg/resvg-js-linux-arm64-musl": "2.2.0", | ||
"@resvg/resvg-js-win32-arm64-msvc": "2.2.0" | ||
} | ||
} |
@@ -7,7 +7,7 @@ # resvg-js | ||
> resvg-js is a high-performance SVG renderer and toolkit, powered by Rust based [resvg](https://github.com/RazrFalcon/resvg/) and [napi-rs](https://github.com/napi-rs/napi-rs). | ||
> resvg-js is a high-performance SVG renderer and toolkit, powered by Rust based [resvg](https://github.com/RazrFalcon/resvg/), with Node.js backend using [napi-rs](https://github.com/napi-rs/napi-rs), also a pure WebAssmebly backend. | ||
## Features | ||
- Fast, safe and zero dependencies. | ||
- Fast, safe and zero dependencies, with correct output. | ||
- Convert SVG to PNG, includes cropping, scaling and setting the background color. | ||
@@ -18,4 +18,7 @@ - Support system fonts and custom fonts in SVG text. | ||
- `v2`: Support WebAssembly. | ||
- `v2`: Support to get SVG bounding box and crop according to bounding box. | ||
- `v2`: Support for loading images of external links in `<image>`. | ||
- No need for node-gyp and postinstall, the `.node` file has been compiled for you. | ||
- Cross-platform support, including [Apple M Chips](https://www.apple.com/newsroom/2020/11/apple-unleashes-m1/). | ||
- Support for running as native addons in Deno. | ||
@@ -36,4 +39,6 @@ ## Installation | ||
## [Example](example/index.js) | ||
## Example | ||
### [Node.js Example](example/index.js) | ||
This example will load Source Han Serif, and then render the SVG to PNG. | ||
@@ -49,2 +54,14 @@ | ||
### [Deno Example](example/index-deno.js) | ||
```shell | ||
deno run --unstable --allow-read --allow-write --allow-ffi example/index-deno.js | ||
[2022-11-16T15:03:29Z DEBUG resvg_js::fonts] Loaded 1 font faces in 0.067ms. | ||
[2022-11-16T15:03:29Z DEBUG resvg_js::fonts] Font './example/SourceHanSerifCN-Light-subset.ttf':0 found in 0.001ms. | ||
Original SVG Size: 1324 x 687 | ||
Output PNG Size : 1200 x 623 | ||
✨ Done in 66 ms | ||
``` | ||
| SVG | PNG | | ||
@@ -91,5 +108,38 @@ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
### Deno | ||
Starting with [Deno 1.26.1](https://github.com/denoland/deno/releases/tag/v1.26.1), there is support for running Native Addons directly from Node.js. | ||
This allows for performance that is close to that found in Node.js. | ||
```shell | ||
deno run --unstable --allow-read --allow-write --allow-ffi example/index-deno.js | ||
``` | ||
```js | ||
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 = { | ||
fitTo: { | ||
mode: 'width', | ||
value: 1200, | ||
}, | ||
} | ||
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) | ||
``` | ||
### WebAssembly | ||
Although we support the use of Wasm packages in Node.js, this is not recommended. The native addon performs better. | ||
This package also ships a pure WebAssembly artifact built with `wasm-bindgen` to run in browsers. | ||
@@ -101,3 +151,3 @@ #### Browser | ||
<script> | ||
;(async function () { | ||
(async function () { | ||
// The Wasm must be initialized first | ||
@@ -122,5 +172,5 @@ await resvg.initWasm(fetch('https://unpkg.com/@resvg/resvg-wasm/index_bg.wasm')) | ||
See [playground](playground/index.html), it is also possible to [call Wasm in Node.js](example/wasm-node.js), but there is a performance penalty and this is not recommended. | ||
See [playground](playground/index.html), it is also possible to [call Wasm in Node.js](example/wasm-node.js), but it is slower. | ||
## Benchmark | ||
## Sample Benchmark | ||
@@ -130,12 +180,12 @@ ```shell | ||
resvg-js(Rust): | ||
12 ops/s, ±22.66% | fastest 🚀 | ||
12 ops/s | ||
sharp: | ||
9 ops/s, ±64.52% | 25% slower | ||
9 ops/s | ||
skr-canvas(Rust): | ||
7 ops/s, ±3.72% | 41.67% slower | ||
7 ops/s | ||
svg2img(canvg and node-canvas): | ||
6 ops/s, ±16.94% | slowest, 50% slower | ||
6 ops/s | ||
``` | ||
@@ -142,0 +192,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
42881
177
285