Scene.import
Imports an animation, SVG, image or audio into the scene.
Scene.import() method
This method has 4 overloads:
Imports a Lottie animation or an SVG into the scene
Imports an image from a URL into the scene
Imports audio into the scene
Imports an animation, SVG, image or audio into the scene
Overload 1: Imports a Lottie animation or an SVG into the scene
Signature:
import(opts: (ImportFromContent | ImportFromURL) & {
type: 'LOTTIE' | 'SVG';
}): Promise<SceneLayer>;Parameters
Parameter | Type | Description |
|---|---|---|
opts | (ImportFromContent | ImportFromURL) & { type: 'LOTTIE' | 'SVG'; } | Options for importing the animation or SVG |
Returns:
Promise<SceneLayer>
A promise that resolves to a scene layer holding the imported content
Remarks
The promise rejects if the import fails.
Example
const layer = await scene.import({ type: "LOTTIE", url: "https://example.com/animation.json" });Overload 2: Imports an image from a URL into the scene
Signature:
import(opts: ImportFromURL & {
type: 'IMAGE';
}): Promise<ImageLayer>;Parameters
Parameter | Type | Description |
|---|---|---|
opts | ImportFromURL & { type: 'IMAGE'; } | Options for importing the image |
Returns:
Promise<ImageLayer>
A promise that resolves to the new image layer
Remarks
The promise rejects if the import fails.
Example
const layer = await scene.import({ type: "IMAGE", url: "https://example.com/image.png" });Overload 3: Imports audio into the scene
Signature:
import(opts: (ImportFromContent | ImportFromURL) & {
type: 'AUDIO';
}): Promise<AudioLayer>;Parameters
Parameter | Type | Description |
|---|---|---|
opts | (ImportFromContent | ImportFromURL) & { type: 'AUDIO'; } | Options for importing the audio, from base64 content or a URL |
Returns:
Promise<AudioLayer>
A promise that resolves to the new audio layer
Remarks
The layer starts at the scene's start frame and lasts as long as the audio.
The promise rejects if the import fails, for example because the format is not supported, the file is over 20 MB or the audio cannot be decoded. A failed import adds nothing to the scene.
Example
const layer = await scene.import({ type: "AUDIO", content: base64 });Overload 4: Imports an animation, SVG, image or audio into the scene
Signature:
import(opts: ImportFromContent | ImportFromURL): Promise<SceneLayer | ImageLayer | AudioLayer>;Parameters
Parameter | Type | Description |
|---|---|---|
opts | Options for importing the content |
Returns:
Promise<SceneLayer | ImageLayer | AudioLayer>
A promise that resolves to the new layer
Remarks
Use this form when type is only known at runtime. The result is a SceneLayer for LOTTIE and SVG, an ImageLayer for IMAGE, and an AudioLayer for AUDIO. The promise rejects if the import fails.