Search by

aarsteinmedia / lottie-php

johanaarstein

There is no license information available for the latest version (0.1.2) of this package.

Create still SVGs from Lottie Animations on the backend, for previews.

Package info

github.com/aarsteinmedia/lottie-php

pkg:composer/aarsteinmedia/lottie-php

Statistics

Installs: 41

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

0.1.2 2026-10-11 10:53 UTC

This package is auto-updated.

Last update: 2026-10-11 10:54:57 UTC


README

Render still SVG frames from Lottie animations on the server — useful for previews, thumbnails, and CMS integrations without a browser runtime.

Supports Lottie JSON (.json) and dotLottie (.lottie) files.

Requirements

  • PHP 8.1+
  • ext-zip (for .lottie archives)

Installation

composer require aarsteinmedia/lottie-php

Usage

Render a single frame to an SVG string:

use LottiePHP\LottieToSVG;

$svg = LottieToSVG::renderFrame('/path/to/animation.json');

By default, the middle frame is rendered. Pass a frame index to pick another:

$svg = LottieToSVG::renderFrame('/path/to/animation.json', frame: 0);

Optional renderer settings (size, aspect ratio, CSS class, etc.):

$svg = LottieToSVG::renderFrame('/path/to/animation.lottie', [
    'width' => 512,
    'height' => 512,
    'preserveAspectRatio' => 'xMidYMid meet',
], frame: 0);

Batch rendering

When rendering many frames from the same file, load once and reuse the animation instance:

$anim = LottieToSVG::loadCached('/path/to/animation.json');

foreach ([0, 15, 30] as $frame) {
    $svg = LottieToSVG::renderFrameFromAnimation($anim, $frame);
}

loadCached() skips re-parsing while the file (path, modification time and size) and renderer settings are unchanged. renderFrame() uses it automatically.

The cache keeps the most recently used animation only, since a parsed animation can take tens of MB. Adjust it for your workload:

LottieToSVG::setCacheSize(4); // keep up to 4 animations (least recently used is evicted)
LottieToSVG::setCacheSize(0); // disable caching, e.g. for one-off thumbnail jobs
LottieToSVG::clearCache();    // free everything now

Development

Clone the repo, run composer install, then start the visual smoke-test UI:

composer visual:up

Open http://localhost:8000 to browse sample animations and inspect rendered SVG output.

Other scripts: composer lint, composer visual:down, composer visual:logs.