Skip to content

Commit

Permalink
0.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
twlite committed Dec 17, 2023
1 parent a004ef2 commit da9a214
Show file tree
Hide file tree
Showing 20 changed files with 1,147 additions and 267 deletions.
108 changes: 54 additions & 54 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,59 +162,59 @@ jobs:
name: bindings-${{ matrix.settings.target }}
path: ${{ env.APP_NAME }}.*.node
if-no-files-found: error
build-freebsd:
runs-on: macos-12
name: Build FreeBSD
steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: Build
id: build
uses: vmactions/freebsd-vm@v0
env:
DEBUG: napi:*
RUSTUP_HOME: /usr/local/rustup
CARGO_HOME: /usr/local/cargo
RUSTUP_IO_THREADS: 1
with:
envs: DEBUG RUSTUP_HOME CARGO_HOME RUSTUP_IO_THREADS
usesh: true
mem: 3000
prepare: |
pkg install -y -f curl node libnghttp2 llvm cmake # Install the llvm package to fix the libclang error
curl -qL https://www.npmjs.com/install.sh | sh
npm install --location=global --ignore-scripts yarn
curl https://sh.rustup.rs -sSf --output rustup.sh
sh rustup.sh -y --profile minimal --default-toolchain beta
rustup component add rustfmt
export PATH="/usr/local/cargo/bin:$PATH"
echo "~~~~ rustc --version ~~~~"
rustc --version
echo "~~~~ node -v ~~~~"
node -v
echo "~~~~ yarn --version ~~~~"
yarn --version
run: |
export PATH="/usr/local/cargo/bin:$PATH"
pwd
ls -lah
whoami
env
freebsd-version
yarn install
yarn build
strip -x *.node
yarn test
rm -rf node_modules
rm -rf target
rm -rf .yarn/cache
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: bindings-freebsd
path: ${{ env.APP_NAME }}.*.node
if-no-files-found: error
# build-freebsd:
# runs-on: macos-12
# name: Build FreeBSD
# steps:
# - uses: actions/checkout@v3
# with:
# submodules: true
# - name: Build
# id: build
# uses: vmactions/freebsd-vm@v0
# env:
# DEBUG: napi:*
# RUSTUP_HOME: /usr/local/rustup
# CARGO_HOME: /usr/local/cargo
# RUSTUP_IO_THREADS: 1
# with:
# envs: DEBUG RUSTUP_HOME CARGO_HOME RUSTUP_IO_THREADS
# usesh: true
# mem: 3000
# prepare: |
# pkg install -y -f curl node libnghttp2 llvm cmake # Install the llvm package to fix the libclang error
# curl -qL https://www.npmjs.com/install.sh | sh
# npm install --location=global --ignore-scripts yarn
# curl https://sh.rustup.rs -sSf --output rustup.sh
# sh rustup.sh -y --profile minimal --default-toolchain beta
# rustup component add rustfmt
# export PATH="/usr/local/cargo/bin:$PATH"
# echo "~~~~ rustc --version ~~~~"
# rustc --version
# echo "~~~~ node -v ~~~~"
# node -v
# echo "~~~~ yarn --version ~~~~"
# yarn --version
# run: |
# export PATH="/usr/local/cargo/bin:$PATH"
# pwd
# ls -lah
# whoami
# env
# freebsd-version
# yarn install
# yarn build
# strip -x *.node
# yarn test
# rm -rf node_modules
# rm -rf target
# rm -rf .yarn/cache
# - name: Upload artifact
# uses: actions/upload-artifact@v3
# with:
# name: bindings-freebsd
# path: ${{ env.APP_NAME }}.*.node
# if-no-files-found: error
test-macOS-windows-binding:
name: Test bindings on ${{ matrix.settings.target }} - node@${{ matrix.node }}
needs:
Expand Down Expand Up @@ -460,7 +460,7 @@ jobs:
name: Publish
runs-on: ubuntu-latest
needs:
- build-freebsd
# - build-freebsd
- test-macOS-windows-binding
- test-linux-x64-gnu-binding
- test-linux-x64-musl-binding
Expand Down
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ yarn.lock
.yarn
__test__
renovate.json
example
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ crate-type = ["cdylib"]
napi = { version = "2.12.2", default-features = false, features = ["napi4"] }
napi-derive = "2.12.2"
visioncortex = "0.8.6"
vtracer = "0.6.3"
fastrand = "1.8"
image = "0.24.7"

[build-dependencies]
napi-build = "2.0.1"
Expand Down
25 changes: 19 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@ import {
Hierarchial,
PathSimplifyMode,
} from '@neplex/vectorizer';
import { Transformer } from '@napi-rs/image';
import { readFile, writeFile } from 'node:fs/promises';

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

const svg = await vectorize(pixels, {
width: IMAGE_WIDTH,
height: IMAGE_HEIGHT,
colorMode: ColorMode.Color,
colorPrecision: 6,
filterSpeckle: 4,
Expand All @@ -45,6 +42,24 @@ await writeFile('./vector.svg', svg);

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

## API

### `vectorize(data: Buffer, config?: Config | Preset): Promise<string>`

Takes an image buffer and returns a promise that resolves to an SVG string.

### `vectorizeSync(data: Buffer, config?: Config | Preset): string`

Takes an image buffer and returns an SVG string synchronously.

### `vectorizeRaw(data: Buffer, args: RawDataConfig, config?: Config | Preset): Promise<string>`

Takes a raw pixel data buffer and returns a promise that resolves to an SVG string.

### `vectorizeRawSync(data: Buffer, args: RawDataConfig, config?: Config | Preset): string`

Takes a raw pixel data buffer and returns an SVG string synchronously.

## Demo

Generated under the following configuration:
Expand All @@ -60,9 +75,7 @@ Generated under the following configuration:
mode: PathSimplifyMode.Spline,
layerDifference: 6,
lengthThreshold: 4,
maxIterations: 2,
width: 1052,
height: 774
maxIterations: 2
}
```

Expand Down
5 changes: 5 additions & 0 deletions __test__/data/result-bw.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion __test__/data/result-firefox.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit da9a214

Please sign in to comment.