npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

lottie-nodejs

v1.1.5

Published

Lottie is a AE render library for Node.js

Downloads

15,827

Readme

Lottie for Node.js

Lottie is a AE render library for Node.js that parses Adobe After Effects animations exported as json with Bodymovin 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.

Example4

Installation

# 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.
// 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.

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

Replace placeholder images and text, etc.

  • Modify the Text in the lottie json data.
anim.replaceText('_xxx_', 'hello world');
  • Modify the Image in the lottie json data.
// param: id, newpath
anim.replaceAsset(17, path.join(__dirname, 'xx.jpg'));
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

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.
// 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;
  1. Run the demo script.
npm run demo

Run the lottie-web effect as a comparison

  1. Install the serve package globally
npm i -g serve
  1. 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