Babashka (Clojure) CLI tool that optimizes Lottie JSON animation files by compressing embedded images, truncating float precision, stripping editor metadata, and minifying output.
The install script checks that all requirements are present before downloading.
curl -fsSL https://raw.githubusercontent.com/ampersanda/lottie-optimize-babashka/main/install.sh | bashThe following must be installed before running the install script:
- Babashka (bb)
- ImageMagick (magick)
- libwebp (cwebp) -- optional but recommended
brew install borkdude/brew/babashka imagemagick webpThe script installs optimize-lottie to ~/.local/bin. Make sure it is in your PATH:
export PATH="${HOME}/.local/bin:${PATH}"rm ~/.local/bin/optimize-lottieIf installed via the install script:
# Basic (images downscaled to canvas size, WebP q80)
optimize-lottie -i animation.json
# Lossless (pixel-perfect, no quality loss)
optimize-lottie -i animation.json -o output.json --lossless
# Custom quality and max image size
optimize-lottie -i animation.json -q 95 -s 512
# Reduce framerate
optimize-lottie -i animation.json --fps 30Or run directly with Babashka:
bb optimize-lottie.bb -i animation.json
bb optimize-lottie.bb -i animation.json -o output.json --lossless
bb optimize-lottie.bb -i animation.json -q 95 -s 512
bb optimize-lottie.bb -i animation.json --fps 30| Flag | Description | Default |
|---|---|---|
-i, --input |
Input Lottie JSON file | required |
-o, --output |
Output file path | <input>.optimized.json |
-s, --max-image-size |
Max image dimension (px) | canvas size |
-q, --webp-quality |
WebP quality 0-100 | 80 |
-p, --precision |
Float decimal places | 3 |
-f, --fps |
Target framerate | keep original |
-l, --lossless |
Lossless WebP | false |
Full-screen looping confetti animation examples located in example/.
Warning
All examples symlink to animations/confetti.json. Changes to that file are reflected immediately across all example projects.
Uses SwiftUI + lottie-ios (SPM).
cd example/ios/LottieExample
open LottieExample.xcodeprojXcode resolves the Lottie SPM dependency automatically. Select a simulator or device and run.
Uses Jetpack Compose + lottie-compose.
cd example/android
./gradlew installDebug
adb shell am start -n com.example.lottieexample/.MainActivityOr open the example/android folder in Android Studio.
Uses lottie with Very Good Analysis. Tested on iOS, Android, and macOS.
cd example/flutter
flutter pub get
flutter runUses ClojureDart with lottie.
cd example/clojuredart
clj -M:cljd flutter- Image compression - Downscales embedded PNG images to fit the animation canvas, converts to WebP (or keeps PNG if smaller), picks the smallest result
- Layer transform adjustment - Updates asset dimensions to match resized pixels, then compensates image layers by scaling anchor points and scale transforms so rendering stays correct on both iOS and Android
- Float truncation - Reduces excessive decimal places in keyframe data
- Metadata removal - Strips After Effects editor-only properties (
mn) - JSON minification - Removes whitespace
Typical results: ~80-94% file size reduction depending on quality settings.