Skip to content

Commit da9a214

Browse files
committed
0.0.3
1 parent a004ef2 commit da9a214

20 files changed

Lines changed: 1147 additions & 267 deletions

.github/workflows/CI.yml

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -162,59 +162,59 @@ jobs:
162162
name: bindings-${{ matrix.settings.target }}
163163
path: ${{ env.APP_NAME }}.*.node
164164
if-no-files-found: error
165-
build-freebsd:
166-
runs-on: macos-12
167-
name: Build FreeBSD
168-
steps:
169-
- uses: actions/checkout@v3
170-
with:
171-
submodules: true
172-
- name: Build
173-
id: build
174-
uses: vmactions/freebsd-vm@v0
175-
env:
176-
DEBUG: napi:*
177-
RUSTUP_HOME: /usr/local/rustup
178-
CARGO_HOME: /usr/local/cargo
179-
RUSTUP_IO_THREADS: 1
180-
with:
181-
envs: DEBUG RUSTUP_HOME CARGO_HOME RUSTUP_IO_THREADS
182-
usesh: true
183-
mem: 3000
184-
prepare: |
185-
pkg install -y -f curl node libnghttp2 llvm cmake # Install the llvm package to fix the libclang error
186-
curl -qL https://www.npmjs.com/install.sh | sh
187-
npm install --location=global --ignore-scripts yarn
188-
curl https://sh.rustup.rs -sSf --output rustup.sh
189-
sh rustup.sh -y --profile minimal --default-toolchain beta
190-
rustup component add rustfmt
191-
export PATH="/usr/local/cargo/bin:$PATH"
192-
echo "~~~~ rustc --version ~~~~"
193-
rustc --version
194-
echo "~~~~ node -v ~~~~"
195-
node -v
196-
echo "~~~~ yarn --version ~~~~"
197-
yarn --version
198-
run: |
199-
export PATH="/usr/local/cargo/bin:$PATH"
200-
pwd
201-
ls -lah
202-
whoami
203-
env
204-
freebsd-version
205-
yarn install
206-
yarn build
207-
strip -x *.node
208-
yarn test
209-
rm -rf node_modules
210-
rm -rf target
211-
rm -rf .yarn/cache
212-
- name: Upload artifact
213-
uses: actions/upload-artifact@v3
214-
with:
215-
name: bindings-freebsd
216-
path: ${{ env.APP_NAME }}.*.node
217-
if-no-files-found: error
165+
# build-freebsd:
166+
# runs-on: macos-12
167+
# name: Build FreeBSD
168+
# steps:
169+
# - uses: actions/checkout@v3
170+
# with:
171+
# submodules: true
172+
# - name: Build
173+
# id: build
174+
# uses: vmactions/freebsd-vm@v0
175+
# env:
176+
# DEBUG: napi:*
177+
# RUSTUP_HOME: /usr/local/rustup
178+
# CARGO_HOME: /usr/local/cargo
179+
# RUSTUP_IO_THREADS: 1
180+
# with:
181+
# envs: DEBUG RUSTUP_HOME CARGO_HOME RUSTUP_IO_THREADS
182+
# usesh: true
183+
# mem: 3000
184+
# prepare: |
185+
# pkg install -y -f curl node libnghttp2 llvm cmake # Install the llvm package to fix the libclang error
186+
# curl -qL https://www.npmjs.com/install.sh | sh
187+
# npm install --location=global --ignore-scripts yarn
188+
# curl https://sh.rustup.rs -sSf --output rustup.sh
189+
# sh rustup.sh -y --profile minimal --default-toolchain beta
190+
# rustup component add rustfmt
191+
# export PATH="/usr/local/cargo/bin:$PATH"
192+
# echo "~~~~ rustc --version ~~~~"
193+
# rustc --version
194+
# echo "~~~~ node -v ~~~~"
195+
# node -v
196+
# echo "~~~~ yarn --version ~~~~"
197+
# yarn --version
198+
# run: |
199+
# export PATH="/usr/local/cargo/bin:$PATH"
200+
# pwd
201+
# ls -lah
202+
# whoami
203+
# env
204+
# freebsd-version
205+
# yarn install
206+
# yarn build
207+
# strip -x *.node
208+
# yarn test
209+
# rm -rf node_modules
210+
# rm -rf target
211+
# rm -rf .yarn/cache
212+
# - name: Upload artifact
213+
# uses: actions/upload-artifact@v3
214+
# with:
215+
# name: bindings-freebsd
216+
# path: ${{ env.APP_NAME }}.*.node
217+
# if-no-files-found: error
218218
test-macOS-windows-binding:
219219
name: Test bindings on ${{ matrix.settings.target }} - node@${{ matrix.node }}
220220
needs:
@@ -460,7 +460,7 @@ jobs:
460460
name: Publish
461461
runs-on: ubuntu-latest
462462
needs:
463-
- build-freebsd
463+
# - build-freebsd
464464
- test-macOS-windows-binding
465465
- test-linux-x64-gnu-binding
466466
- test-linux-x64-musl-binding

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ yarn.lock
1111
.yarn
1212
__test__
1313
renovate.json
14+
example

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ crate-type = ["cdylib"]
1111
napi = { version = "2.12.2", default-features = false, features = ["napi4"] }
1212
napi-derive = "2.12.2"
1313
visioncortex = "0.8.6"
14-
vtracer = "0.6.3"
14+
fastrand = "1.8"
15+
image = "0.24.7"
1516

1617
[build-dependencies]
1718
napi-build = "2.0.1"

README.md

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,12 @@ import {
1717
Hierarchial,
1818
PathSimplifyMode,
1919
} from '@neplex/vectorizer';
20-
import { Transformer } from '@napi-rs/image';
2120
import { readFile, writeFile } from 'node:fs/promises';
2221

2322
const src = await readFile('./raster.png');
2423
const pixels = await new Transformer(src).rawPixels();
2524

2625
const svg = await vectorize(pixels, {
27-
width: IMAGE_WIDTH,
28-
height: IMAGE_HEIGHT,
2926
colorMode: ColorMode.Color,
3027
colorPrecision: 6,
3128
filterSpeckle: 4,
@@ -45,6 +42,24 @@ await writeFile('./vector.svg', svg);
4542

4643
If you want to use synchronous API, you can use `vectorizeSync` instead.
4744

45+
## API
46+
47+
### `vectorize(data: Buffer, config?: Config | Preset): Promise<string>`
48+
49+
Takes an image buffer and returns a promise that resolves to an SVG string.
50+
51+
### `vectorizeSync(data: Buffer, config?: Config | Preset): string`
52+
53+
Takes an image buffer and returns an SVG string synchronously.
54+
55+
### `vectorizeRaw(data: Buffer, args: RawDataConfig, config?: Config | Preset): Promise<string>`
56+
57+
Takes a raw pixel data buffer and returns a promise that resolves to an SVG string.
58+
59+
### `vectorizeRawSync(data: Buffer, args: RawDataConfig, config?: Config | Preset): string`
60+
61+
Takes a raw pixel data buffer and returns an SVG string synchronously.
62+
4863
## Demo
4964

5065
Generated under the following configuration:
@@ -60,9 +75,7 @@ Generated under the following configuration:
6075
mode: PathSimplifyMode.Spline,
6176
layerDifference: 6,
6277
lengthThreshold: 4,
63-
maxIterations: 2,
64-
width: 1052,
65-
height: 774
78+
maxIterations: 2
6679
}
6780
```
6881

__test__/data/result-bw.svg

Lines changed: 5 additions & 0 deletions
Loading

__test__/data/result-firefox.svg

Lines changed: 1 addition & 1 deletion
Loading

0 commit comments

Comments
 (0)