Skip to content

Commit e0e764e

Browse files
committed
0.0.1
1 parent 24540f9 commit e0e764e

File tree

6 files changed

+63
-10
lines changed

6 files changed

+63
-10
lines changed

README.md

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,82 @@
22

33
![https://github.com/gomander/napi-webp-animation/actions](https://github.com/gomander/napi-webp-animation/workflows/CI/badge.svg)
44

5-
> A WebP animation package for NodeJS using Rust
5+
> A fully typed WebP animation package for NodeJS using Rust
6+
7+
## ⚠️ This project is a work-in-progress!
8+
9+
This package is a N-API wrapper for the [`webp-animation`](https://crates.io/crates/webp-animation) Rust crate, but does not yet support all its features.
10+
By virtue of being built with NAPI-RS, this package is fully typed, and compatible with ESM and CJS.
611

712
## Install
813

914
```sh
1015
npm install napi-webp-animation
1116
```
1217

18+
## Usage
19+
20+
```js
21+
import { WebpEncoder } from 'napi-webp-animation'
22+
23+
// Create an encoder instance with width and height
24+
const encoder = new WebpEncoder(100, 100)
25+
26+
// Set the frame rate of the animated WebP - default 30
27+
encoder.setFrameRate(24)
28+
29+
// Add your frames as buffers
30+
for (const frameBuffer of frameBuffers) {
31+
encoder.addFrame(frameBuffer)
32+
}
33+
34+
// Encode the animated WebP and write it to file!
35+
const data = await encoder.writeToFile('output.webp')
36+
37+
// Or get the data as a buffer without writing it to file
38+
const data = await encoder.getBuffer()
39+
40+
// Output options can be set on `writeToFile`, `getBuffer`
41+
await encoder.writeToFile('output.webp', {
42+
lossless: false, // default true
43+
quality: 75, // 0 (fast) - 100 (slower) - default 1
44+
method: 3, // 0 (fast) - 6 (slower) - default 4
45+
loopCount: 1 // 0 = infinite, n > 0 = play n times - default 0
46+
})
47+
48+
// Synchronous methods are also available, and also support options
49+
encoder.writeToFileSync('output.webp')
50+
encoder.getBufferSync()
51+
52+
// Clear the encoder's frames, set the dimensions, or set the options
53+
encoder.clearFrames()
54+
encoder.setDimensions(480, 270)
55+
```
56+
1357
## Support matrix
1458

1559
| | node18 | node20 | node22 |
1660
| ---------------- | ------ | ------ | ------ |
17-
| Windows x64 ||||
1861
| Linux x64 gnu ||||
1962
| macOS x64 ||||
2063
| macOS aarch64 ||||
64+
| Windows x64 ||||
65+
66+
## Contributing
2167

68+
Issues and pull requests are welcome!
69+
70+
Particularly, I would love help setting up the CI to build for more platforms.
2271

2372
## Developing
2473

25-
- Install latest [Rust](https://rustup.rs/). If on Windows, use WSL for an easier time.
26-
- Install `NodeJS@18+`. LTS versions suggested.
27-
- Install `pnpm` and dependencies with `pnpm i`.
74+
- If on Windows, recommend using [WSL](https://learn.microsoft.com/en-us/windows/wsl/install)
75+
- Install latest [Rust](https://rustup.rs/)
76+
- Install latest LTS [Node](https://nodejs.org/en/download)
77+
- Install pnpm with `npm i -g pnpm`
78+
- Install dependencies with `pnpm i`
79+
80+
Make your changes, and run the tests with `pnpm test`.
2881

2982
You can then compile the rust code with `pnpm build`.
3083

npm/darwin-arm64/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"files": [
1212
"napi-webp-animation.darwin-arm64.node"
1313
],
14-
"description": "A WebP animation package for NodeJS using Rust",
14+
"description": "A fully typed WebP animation package for NodeJS using Rust",
1515
"keywords": [
1616
"napi",
1717
"napi-rs",

npm/darwin-x64/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"files": [
1212
"napi-webp-animation.darwin-x64.node"
1313
],
14-
"description": "A WebP animation package for NodeJS using Rust",
14+
"description": "A fully typed WebP animation package for NodeJS using Rust",
1515
"keywords": [
1616
"napi",
1717
"napi-rs",

npm/linux-x64-gnu/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"files": [
1212
"napi-webp-animation.linux-x64-gnu.node"
1313
],
14-
"description": "A WebP animation package for NodeJS using Rust",
14+
"description": "A fully typed WebP animation package for NodeJS using Rust",
1515
"keywords": [
1616
"napi",
1717
"napi-rs",

npm/win32-x64-msvc/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"files": [
1212
"napi-webp-animation.win32-x64-msvc.node"
1313
],
14-
"description": "A WebP animation package for NodeJS using Rust",
14+
"description": "A fully typed WebP animation package for NodeJS using Rust",
1515
"keywords": [
1616
"napi",
1717
"napi-rs",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "napi-webp-animation",
33
"version": "0.0.1",
4-
"description": "A WebP animation package for NodeJS using Rust",
4+
"description": "A fully typed WebP animation package for NodeJS using Rust",
55
"exports": {
66
".": {
77
"import": {

0 commit comments

Comments
 (0)