Edit in the browser, render on your server
The user edits in the browser, and your server renders the final image. Sealpixel covers two parts of this. The editor turns the original into an edit log, and the renderer turns the original and the log into the file. Everything between them belongs to your application.
What the editor hands out
The editor takes the original as its src. It reads the original once, computes the size and the sha256 that go into the log, and previews every edit on a working copy. When the user is done, the editor hands out the log and the position in it:
const { log, index } = editor.getEditLog();Store both. After an undo, the log still holds the step that the user took back, and index says where the edit stands. The same object resumes the editor at that step (Resume editing).
What the renderer needs
The renderer needs these inputs:
- The original, byte for byte: the file that the editor loaded. A scaled or re-encoded copy has another sha256 and another size, and the renderer refuses it with
SOURCE_MISMATCH. - The log.
- The index, as
upTo. Without it, a step that the user took back reaches the render. - The bytes of every font and image that the log uses, as
assets. The editor had them in the browser, and the renderer loads none itself. An uploaded sticker is inlog.assets, with its sha256 but without its bytes. See Assets.
const result = await renderer.render({
original,
editLog: saved.log,
upTo: saved.index,
output: { format: 'image/jpeg', quality: 0.9 },
});Register the same plugins and the same pluginOptions as the editor. A plugin that only the editor has makes the log fail with UNKNOWN_PLUGIN.
What comes back
result.bytes is the same file that a browser export of the same log at the same index produces. result.hash is its sha256, so you can compare the two. result.width and result.height are the size of the render. Store or return the file the way your application needs.