Skip to content

Commit

Permalink
doc: v2.1.0 changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
yisibl committed Jul 3, 2022
1 parent a57b2d0 commit c6eb2c0
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 9 deletions.
67 changes: 66 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,76 @@ This changelog also contains important changes in dependencies.

## [Unreleased]

### Added

- Add `imagesToResolve()` and `resolveImage()` APIs to load image URL. By @zimond in [#102](https://github.com/yisibl/resvg-js/pull/102)

- Supports PNG, JPEG and GIF formats.
- This only works for `xlink:href` starting with `http://` or `https://`.
- See [example](example/image-url.js) for more details.

In order to support loading image URL, we forked the rust side of resvg and made some improvements.

Now please witness the magic moment:

![load image URL Demo](https://user-images.githubusercontent.com/2784308/168537647-6787dfc3-49b6-42bb-be5e-35ddba8072d9.png)

- Add `innerBBox()` API. By @yisibl in [#105](https://github.com/yisibl/resvg-js/pull/105)

Calculate a maximum bounding box of all visible elements in this SVG. (Note: path bounding box are approx values).

- Add `getBBox()` API. By @yisibl in [#108](https://github.com/yisibl/resvg-js/pull/108)

We designed it to correspond to the [`SVGGraphicsElement.getBBox()`](https://developer.mozilla.org/en-US/docs/Web/API/SVGGraphicsElement/getBBox) method in the browser.

This is different from the `innerBBox()` API, by default it does apply transform calculations and gets the BBox with curves exactly. This works well in most use cases, the only drawback is that it does not calculate BBoxes with stroke correctly.

- Add `cropByBBox()` API. By @yisibl in [#108](https://github.com/yisibl/resvg-js/pull/108)

With this API, we can crop the generated bitmap based on the BBox(bounding box).

<img width="550" alt="cropByBBox Demo" src="https://user-images.githubusercontent.com/2784308/177039185-5c1a8014-9e44-4c18-aae2-8f509163da56.gif">

```js
const fs = require('fs')
const { Resvg } = require('@resvg/resvg-js')
const svg = '' // some SVG string or file.
const resvg = new Resvg(svg)
const innerBBox = resvg.innerBBox()
const bbox = resvg.getBBox()

// Crop the bitmap according to bbox,
// The argument to the `.cropByBBox()` method accepts `bbox` or `innerBBox`.
if (bbox) resvg.cropByBBox(bbox)
const pngData = resvg.render()
const pngBuffer = pngData.asPng()

console.info('SVG BBox: ', `${bbox.width} x ${bbox.height}`)
fs.writeFileSync('out.png', pngBuffer)
```

- feat: upgrade svgtypes to 0.8.1 to support [4 digits and 8 digits](https://www.w3.org/TR/css-color-4/#hex-notation) hex colors. By @yisibl in [#127](https://github.com/yisibl/resvg-js/pull/127)

### Changed

- feat: return undefined if bbox is invalid. By @zimond in [#110](https://github.com/yisibl/resvg-js/pull/110)
- chore: use jimp-compact instead of jimp.
- fix(deps): update rust crate napi to 2.5.0.
- fix(deps): update rust crate mimalloc-rust to 0.2.
- chore: export AR in android pipeline.
- style: rust indent changed from 2 to 4 spaces.

## [2.0.1] - 2022-05-07

### Added

- feat: add bbox related API. @zimond in [#90](https://github.com/yisibl/resvg-js/pull/90)

This version does not yet implement Node.js or Wasm bindings, so it is not available for now.

### Fixed

- fix: rebuild Wasm to solve the problem of not working in the browser
- fix: rebuild Wasm to solve the problem of not working in the browser.

## [2.0.0] - 2022-04-30

Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,23 +166,27 @@ Running "resize width" suite...
- Install latest `Rust`
- Install `Node.js@10+` which fully supported `Node-API`
- Install `wasm-pack`

```bash
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
```

Normally `wasm-pack` will install `wasm-bindgen` automatically, but if the installation [fails due to network reasons](https://github.com/rustwasm/wasm-pack-template/issues/44#issuecomment-521657516), please try to install it manually.
```bash
cargo install wasm-bindgen-cli

```bash
cargo install wasm-bindgen-cli
```

On computers with Apple M chips, the following error message may appear:

> Error: failed to download from https://github.com/WebAssembly/binaryen/releases/download/version_90/binaryen-version_90-x86_64-apple-darwin.tar.gz
Please install binaryen manually:

```bash
brew install binaryen
```


### Build Node.js bindings

```bash
Expand Down
7 changes: 6 additions & 1 deletion example/image-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ const fetch = require('node-fetch')
const { Resvg } = require('../index')

async function main() {
const svg = await promises.readFile(join(__dirname, './url.svg'))
const svg = `
<!-- From https://octodex.github.com/nyantocat/ -->
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<image href="https://octodex.github.com/images/nyantocat.gif" width="500" height="500"/>
</svg>
`
const opts = {
font: {
loadSystemFonts: false, // It will be faster to disable loading system fonts.
Expand Down
4 changes: 0 additions & 4 deletions example/url.svg

This file was deleted.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
"jimp-compact": "^0.16.1-2",
"lint-staged": "^12.5.0",
"npm-run-all": "^4.1.5",
"node-fetch": "2.x",
"prettier": "^2.7.1",
"sharp": "^0.30.7",
"typescript": "^4.7.4"
Expand Down
25 changes: 25 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2633,6 +2633,13 @@ node-addon-api@^5.0.0:
resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-5.0.0.tgz#7d7e6f9ef89043befdb20c1989c905ebde18c501"
integrity sha512-CvkDw2OEnme7ybCykJpVcKH+uAOLV2qLqiyla128dN9TkEWfrYmxG6C2boDe5KcNQqZF3orkqzGgOMvZ/JNekA==

node-fetch@2.x:
version "2.6.7"
resolved "https://registry.npmmirror.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad"
integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==
dependencies:
whatwg-url "^5.0.0"

noms@0.0.0:
version "0.0.0"
resolved "https://registry.npmjs.org/noms/-/noms-0.0.0.tgz#da8ebd9f3af9d6760919b27d9cdc8092a7332859"
Expand Down Expand Up @@ -3642,6 +3649,11 @@ to-regex-range@^5.0.1:
dependencies:
is-number "^7.0.0"

tr46@~0.0.3:
version "0.0.3"
resolved "https://registry.npmmirror.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a"
integrity sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==

trim-off-newlines@^1.0.1:
version "1.0.3"
resolved "https://registry.npmmirror.com/trim-off-newlines/download/trim-off-newlines-1.0.3.tgz#8df24847fcb821b0ab27d58ab6efec9f2fe961a1"
Expand Down Expand Up @@ -3816,11 +3828,24 @@ wcwidth@^1.0.1:
dependencies:
defaults "^1.0.3"

webidl-conversions@^3.0.0:
version "3.0.1"
resolved "https://registry.npmmirror.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871"
integrity sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==

well-known-symbols@^2.0.0:
version "2.0.0"
resolved "https://registry.nlark.com/well-known-symbols/download/well-known-symbols-2.0.0.tgz#e9c7c07dbd132b7b84212c8174391ec1f9871ba5"
integrity sha1-6cfAfb0TK3uEISyBdDkewfmHG6U=

whatwg-url@^5.0.0:
version "5.0.0"
resolved "https://registry.npmmirror.com/whatwg-url/-/whatwg-url-5.0.0.tgz#966454e8765462e37644d3626f6742ce8b70965d"
integrity sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==
dependencies:
tr46 "~0.0.3"
webidl-conversions "^3.0.0"

which-boxed-primitive@^1.0.2:
version "1.0.2"
resolved "https://registry.nlark.com/which-boxed-primitive/download/which-boxed-primitive-1.0.2.tgz#13757bc89b209b049fe5d86430e21cf40a89a8e6"
Expand Down

0 comments on commit c6eb2c0

Please sign in to comment.