Creating a Scene From a Blob
In this example, we will show you how to initialize the CreativeEditor SDK with an initial image provided from a blob.
Explore a full code sample on Stackblitz or view the code on Github.
Starting from an existing image allows you to use the editor for customizing individual assets.
This is done by using engine.scene.createFromImage(url: string, dpi = 300, pixelScaleFactor = 1): Promise<number>
and passing a URL as argument.
The dpi
argument sets the dots per inch of the scene.
The pixelScaleFactor
sets the display's pixel scale factor.
First, get hold of a blob
by fetching an image from the web.
This is just for demonstration purposes and your blob
object may come from a different source.
Afterward, create a URL pointing to the blob via URL.createObjectURL
.
Use the created URL as a source for the initial image.
We can retrieve the graphic block id of this initial image using cesdk.engine.block.findByType(type: ObjectType): number[]
.
Note that that function returns an array.
Since there's only a single graphic block in the scene, the block is at index 0
.
We can then manipulate and modify this block.
Here we modify its opacity with cesdk.engine.block.setOpacity(id: number, opacity: number): void
.
See Modifying Scenes for more details.
When starting with an initial image, the scenes page dimensions match the given image, and the scene is configured to be in pixel design units.
To later save your scene, see Saving Scenes.