friday / lottie-node Goto Github PK
View Code? Open in Web Editor NEWExport lottie animations in Node.js
License: MIT License
Export lottie animations in Node.js
License: MIT License
Moving to 2.0.0.
Running the lottie-node examples produces blank images and videos.
Previously this happened when replacing images, but is now happening for all examples.
Images and videos produced contain content
Videos produced are blank, white background throughout without content
Versions:
Operating System:
Ubuntu 20.04, Windows 10 and MacOS 10.15.7
Seeing the recent updates in node-canvas and jsdom. Can you make lottie animations in svg work?
The animation used in the example render is credited as "an animation from lottie-react-native", since I found it in that repo. It may not be significant or enough information for credits and from legal/licencing-aspects.
undefined:6284
elementWidth = this.canvasContext.canvas.width * this.renderConfig.dpr;
^
TypeError: Cannot read property 'canvas' of null
at CanvasRenderer.updateContainerSize (eval at <anonymous> (C:\Users\Snow\lottie\node_modules\lottie-node\index.js:42:3), <anonymous>:6284:43)
at CanvasRenderer.configAnimation (eval at <anonymous> (C:\Users\Snow\lottie\node_modules\lottie-node\index.js:42:3), <anonymous>:6272:10)
at AnimationItem.configAnimation (eval at <anonymous> (C:\Users\Snow\lottie\node_modules\lottie-node\index.js:42:3), <anonymous>:11417:19)
at AnimationItem.setParams (eval at <anonymous> (C:\Users\Snow\lottie\node_modules\lottie-node\index.js:42:3), <anonymous>:11284:14)
at Object.loadAnimation (eval at <anonymous> (C:\Users\Snow\lottie\node_modules\lottie-node\index.js:42:3), <anonymous>:11068:18)
at Object.loadAnimation (eval at <anonymous> (C:\Users\Snow\lottie\node_modules\lottie-node\index.js:42:3), <anonymous>:14282:33)
at C:\Users\Snow\lottie\node_modules\lottie-node\index.js:52:24
at Object.<anonymous> (C:\Users\Snow\lottie\examples\render-png.js:7:19)
at Module._compile (internal/modules/cjs/loader.js:701:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
This library can be used to render Lottie animations with modifications (use animations as templates, allow users to make changes and render the result).
It would be useful to add this to the examples. I don't have any such animations that I can legally use, so contributions are welcome.
More info about how to replace content:
For texts, this is documented here: https://github.com/airbnb/lottie-web/wiki/TextLayer.updateDocumentData
I'm not aware about any official API to replace images. I have been able to use something like this (where data
is an object literal containing the data.json-structure):
// Map of readable names
const paths = {file: 'p', folder: 'u', preserveAspectRatio: 'pr'};
// Filter out images
const images = (data.assets || []).filter(asset => asset[paths.folder]); // Only images have folders
// Change image path to empty string since we've flattened the folder structure
images.forEach(asset => {
asset[paths.folder] = ''; // Set folder to the same directory as data.json
asset[paths.file] = '/path/to/new/image'; // Override image
asset[paths.preserveAspectRatio] = 'xMidYMid meet'; // "Contain" image, See https://github.com/airbnb/lottie-web/issues/1046
});
Note that this code is taken out of context and untested.
Possible animation which can be used:
https://lottiefiles.com/53085-airplane-animation
node-canvas v2 has been released, and jsdom-support is coming. This may not affect this repo since v2 is primarily about font rendering, and lottie uses glyphs. Testing is needed however, and the version strings used may need to be restricted.
render-snapshot.js runs correctly
script fails on window.lottie.loadAnimation with this error:
UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'loadAnimation' of undefined
at /Users/meo/node_modules/lottie-node/index.js:63:24
at /Users/meo/Downloads/render-snapshot.js:11:21
which means that eval didn't create lottie object
node render-snapshot.js test.json test.png
Versions:
Operating System: MacOS 11.1
Tried also on an Azure Function with linux and Node 12.22.11 (different version of jsdom too, 19.0.0) and reported exaxtly the same error
(node:55203) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'loadAnimation' of undefined
at /Users/meo/node_modules/lottie-node/index.js:63:24
at /Users/meo/Downloads/render-snapshot.js:11:21
(Usenode --trace-warnings ...
to show where the warning was created)
(node:55203) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag--unhandled-rejections=strict
(see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:55203) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
I'm using this file that rendering blank video
Tests are always good. Optimally the lottie-node API should be fully covered, but since it's kind of a niche library and I don't even have After Effects myself (I'm running Linux) I'm blocked by #4.
Example of tests that should be possible:
See https://github.com/friday/lottie-node#usage
There are ways to avoid the wrapper. I can't really recall why I wrote it the way I did.
Ex:
const loadAnimation = require('lottie-node');
const loadAnimationWithCustomLottie = require('lottie-node').factory('/path/to/lottie');
Or:
const {loadAnimation} = require('lottie-node');
const loadAnimationWithCustomLottie = require('lottie-node')('/path/to/lottie');
hey @friday thanks for putting your code here. This is a great way to create templates and render on the server.
The problem i have is that if I chose canvas as renderer, I am not able to change text on runtime as it converts text to glyphs and during template creation i am not sure of what all characters to put in hidden layer as suggested by bodymovin. Also there is some issue with masking but that can be taken of during creation.
And if i chose svg as renderer, i cannot export frames as png (i can export them as svg though) on nodejs.
let data = "data:image/svg+xml;base64,";
let svgString = anim.renderer.svgElement.outerHTML;
let base64 = window.btoa(svgString);
let dataURI = data + base64;
Now if i use img onload method to actually use this dataURI as source for image i get error.
Also wanted to know what actually context in rendererSettings does in loadAnimation. Does it writes to the context of canvas on its own? I am not sure how it works.
Any help would be appreciated. thanks again for sharing your library.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.