{"id":13907470,"url":"https://github.com/drawcall/lottie-node","last_synced_at":"2025-04-30T16:05:06.846Z","repository":{"id":42380422,"uuid":"476998195","full_name":"drawcall/lottie-node","owner":"drawcall","description":"Render AE lottie animations file in Node.js","archived":false,"fork":false,"pushed_at":"2022-05-13T01:34:03.000Z","size":6951,"stargazers_count":36,"open_issues_count":2,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-27T01:02:15.392Z","etag":null,"topics":["lottie","lottie-library","lottie-node","lottie-nodejs"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/drawcall.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-04-02T08:47:21.000Z","updated_at":"2025-03-19T01:22:34.000Z","dependencies_parsed_at":"2022-09-05T14:40:32.281Z","dependency_job_id":null,"html_url":"https://github.com/drawcall/lottie-node","commit_stats":null,"previous_names":["wood9/lottie-node"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drawcall%2Flottie-node","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drawcall%2Flottie-node/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drawcall%2Flottie-node/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drawcall%2Flottie-node/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/drawcall","download_url":"https://codeload.github.com/drawcall/lottie-node/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251738458,"owners_count":21635824,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["lottie","lottie-library","lottie-node","lottie-nodejs"],"created_at":"2024-08-06T23:01:57.229Z","updated_at":"2025-04-30T16:05:06.602Z","avatar_url":"https://github.com/drawcall.png","language":"JavaScript","funding_links":[],"categories":["HarmonyOS"],"sub_categories":["Windows Manager"],"readme":"# Lottie for Node.js\n\nLottie 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.\n\nLottie-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.\n\n# documentation\n\nLottie-node is transplanted from lottie-web, so its api is exactly the same as lottie-web.\nView documentation, FAQ, help, examples, and more at [lottie-web](http://airbnb.io/lottie/#/web).\n\n![Example4](./gifs/demo.gif)\n\n# Installation\n\n```bash\n# with npm\nnpm install lottie-nodejs\n```\n\n### Install node-canvas\n\nOh, 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.\n\n# UseAge\n\n- Import lottie-nodejs and node-canvas libraries.\n- Set up Canvas class for lottie-nodejs.\n- Create a Canvas instance for rendering.\n- Lottie loads the animation file and initializes it.\n- Use timer to render lottie framed animation.\n- Render and save the image to the local, or other operations.\n\n```javascript\n// 1. Import lottie-nodejs and node-canvas libraries\nconst lottie = require('lottie-nodejs');\nconst { Canvas, Image } = require('canvas');\n\n// 2. Set up Canvas class for lottie-nodejs\nlottie.setCanvas({\n  Canvas,\n  Image,\n});\n\n// 3. Create a Canvas instance for rendering\nconst canvas = new Canvas(500, 500);\n\n// 4. Lottie loads the animation file and initializes it\nconst anim = lottie.loadAnimation({\n  container: canvas,\n  loop: false,\n  path: path.join(__dirname, './assets/data.json'),\n  // animationData: data\n});\n\n// 5. Use timer to render lottie framed animation\nsetInterval(() =\u003e {\n  anim.render();\n\n  // 6. Render and save the image to the local, or other operations\n  const buffer = canvas.toBuffer('image/png');\n  const file = path.join(__dirname, `./output/imgs/${index++}.png`);\n  fs.outputFile(file, buffer);\n}, 1000 / 30);\n```\n\n#### Of course you can use any api of lottie-web.\n\n```javascript\nanim.goToAndStop(25, true);\nanim.onEnterFrame(...);\n```\n\n#### Replace placeholder images and text, etc.\n\n- Modify the Text in the lottie json data.\n\n```javascript\nanim.replaceText('_xxx_', 'hello world');\n```\n\n- Modify the Image in the lottie json data.\n\n```javascript\n// param: id, newpath\nanim.replaceAsset(17, path.join(__dirname, 'xx.jpg'));\n```\n\n- Use lottie-api for more advanced modifications. [https://github.com/bodymovin/lottie-api](https://github.com/bodymovin/lottie-api)\n\n```javascript\nconst elements = anim.getApi().getKeyPath('comp1,textnode');\nelements.getElements()[0].setText('hahahahah!');\n\n// or\nconst elements = anim.findElements('comp1,textnode');\nelements[0].setText('hahahahah!');\n```\n\n\n# Development\n\nClone the project and install related dependencies\n\n```shell\ngit clone https://github.com/drawcall/lottie-node.git\n```\n\n#### You can run the demo to try out the project.\n\n1. Modify the demo/index.js file and modify the values of i and j to view the demo.\n\n```javascript\n// i from 1 to 4  [1-4]\nconst i = 2; // floder\n// j from 1 to 20 [1-20]\nconst j = 9; // file\nconst num = 50;\nconst delta = 33 * 4;\n```\n\n2. Run the demo script.\n\n```shell\nnpm run demo\n```\n\n#### Run the lottie-web effect as a comparison\n\n1. Install the `serve` package globally\n\n```shell\nnpm i -g serve\n```\n\n2. Execute serve and view the corresponding demo html\n   \u003e modify the values of i and j to view the demo\n\nhttp://localhost:xxxx/demo/test/?i=2\u0026j=9\n\n## License\n\n[MIT License](https://opensource.org/licenses/MIT)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrawcall%2Flottie-node","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrawcall%2Flottie-node","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrawcall%2Flottie-node/lists"}