# lottie-nodejs

> Lottie is a AE render library for Node.js

Latest version **1.1.5** (published 2022-05-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install lottie-nodejs
pnpm add lottie-nodejs
yarn add lottie-nodejs
bun add lottie-nodejs
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.5 |
| Published | 2022-05-13 |
| First published | 2022-04-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 394.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 39 |
| Maintainers | ajiemath |
| Keywords | animation, canvas, after effects, plugin, export |

## Links

- npm: https://www.npmjs.com/package/lottie-nodejs
- Repository: https://github.com/drawcall/lottie-node
- Homepage: https://github.com/drawcall/lottie-node#readme
- Issues: https://github.com/drawcall/lottie-node/issues
- npm.io page: https://npm.io/package/lottie-nodejs

## Dependencies (1)

- [lottie-api](https://npm.io/package/lottie-api.md) ^1.0.3

## Alternatives

- [exif-parser](https://npm.io/package/exif-parser.md) — 3.8M weekly downloads
- [vite-plugin-compression](https://npm.io/package/vite-plugin-compression.md) — 569.5K weekly downloads
- [pica](https://npm.io/package/pica.md) — 442.4K weekly downloads
- [@reportportal/client-javascript](https://npm.io/package/@reportportal/client-javascript.md) — 408.8K weekly downloads
- [@tldraw/state](https://npm.io/package/@tldraw/state.md) — 316.0K weekly downloads

## Recent versions

- 1.1.5 (latest) — 2022-05-13
- 1.1.3 — 2022-05-13
- 1.1.2 — 2022-05-13
- 5.5.99 — 2022-04-20
- 5.5.98 — 2022-04-08
- 5.5.97 — 2022-04-08
- 5.5.96 — 2022-04-08
- 5.5.95 — 2022-04-08
- 5.5.93 — 2022-04-08
- 5.5.92 — 2022-04-08
- 5.5.9 — 2022-04-08
- 6.0.6 — 2022-04-02
- 6.0.5 — 2022-04-02
- 6.0.4 — 2022-04-02
- 6.0.3 — 2022-04-02
- … 2 more at https://npm.io/package/lottie-nodejs/versions

## README

# Lottie for Node.js

Lottie is a AE render library for Node.js that parses [Adobe After Effects](http://www.adobe.com/products/aftereffects.html) animations exported as json with [Bodymovin](https://github.com/airbnb/lottie-web) and renders them natively on web.

Lottie-node is an API for runnig Lottie with the canvas renderer in Node.js, with the help of node-canvas. This is intended for rendering Lottie animations to images or video.

# documentation

Lottie-node is transplanted from lottie-web, so its api is exactly the same as lottie-web.
View documentation, FAQ, help, examples, and more at [lottie-web](http://airbnb.io/lottie/#/web).

![Example4](./gifs/demo.gif)

# Installation

```bash
# with npm
npm install lottie-nodejs
```

### Install node-canvas

Oh, I don't have a built-in node-canvas library by default, you can import it externally and pass it in. This design is mainly for use in conjunction with FFCreator.

# UseAge

- Import lottie-nodejs and node-canvas libraries.
- Set up Canvas class for lottie-nodejs.
- Create a Canvas instance for rendering.
- Lottie loads the animation file and initializes it.
- Use timer to render lottie framed animation.
- Render and save the image to the local, or other operations.

```javascript
// 1. Import lottie-nodejs and node-canvas libraries
const lottie = require('lottie-nodejs');
const { Canvas, Image } = require('canvas');

// 2. Set up Canvas class for lottie-nodejs
lottie.setCanvas({
  Canvas,
  Image,
});

// 3. Create a Canvas instance for rendering
const canvas = new Canvas(500, 500);

// 4. Lottie loads the animation file and initializes it
const anim = lottie.loadAnimation({
  container: canvas,
  loop: false,
  path: path.join(__dirname, './assets/data.json'),
  // animationData: data
});

// 5. Use timer to render lottie framed animation
setInterval(() => {
  anim.render();

  // 6. Render and save the image to the local, or other operations
  const buffer = canvas.toBuffer('image/png');
  const file = path.join(__dirname, `./output/imgs/${index++}.png`);
  fs.outputFile(file, buffer);
}, 1000 / 30);
```

#### Of course you can use any api of lottie-web.

```javascript
anim.goToAndStop(25, true);
anim.onEnterFrame(...);
```

#### Replace placeholder images and text, etc.

- Modify the Text in the lottie json data.

```javascript
anim.replaceText('_xxx_', 'hello world');
```

- Modify the Image in the lottie json data.

```javascript
// param: id, newpath
anim.replaceAsset(17, path.join(__dirname, 'xx.jpg'));
```

- Use lottie-api for more advanced modifications. [https://github.com/bodymovin/lottie-api](https://github.com/bodymovin/lottie-api)

```javascript
const elements = anim.getApi().getKeyPath('comp1,textnode');
elements.getElements()[0].setText('hahahahah!');

// or
const elements = anim.findElements('comp1,textnode');
elements[0].setText('hahahahah!');
```


# Development

Clone the project and install related dependencies

```shell
git clone https://github.com/drawcall/lottie-node.git
```

#### You can run the demo to try out the project.

1. Modify the demo/index.js file and modify the values of i and j to view the demo.

```javascript
// i from 1 to 4  [1-4]
const i = 2; // floder
// j from 1 to 20 [1-20]
const j = 9; // file
const num = 50;
const delta = 33 * 4;
```

2. Run the demo script.

```shell
npm run demo
```

#### Run the lottie-web effect as a comparison

1. Install the `serve` package globally

```shell
npm i -g serve
```

2. Execute serve and view the corresponding demo html
   > modify the values of i and j to view the demo

http://localhost:xxxx/demo/test/?i=2&j=9

## License

[MIT License](https://opensource.org/licenses/MIT)

---
_Source: https://npm.io/package/lottie-nodejs · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
