v8.95.3

Using a custom export button

We can remove the default "Done" button using the enableButtonExport property. Using the willRenderToolbar hook we can add our own custom button.

<!DOCTYPE html>

<head>
    <link rel="stylesheet" href="./pintura.css" />
</head>

<img src="" alt="" />

<style>
    .pintura-editor {
        height: 600px;
    }
</style>

<div id="editor"></div>

<script type="module">
    import {
        appendDefaultEditor,
        processImage,
        createNode,
        appendNode,
        findNode,
    } from './pintura.js';

    const editor = appendDefaultEditor('#editor', {
        src: 'image.jpeg',

        // This removes the default done button
        enableButtonExport: false,
        willRenderToolbar: (toolbar) => {
            // add to right most group
            const buttonGroup = findNode('gamma', toolbar);

            // create a custom button
            const exportButton = createNode('Button', 'export-button', {
                label: 'Save',
                onclick: () => {
                    // tell the editor to process the current image
                    editor.processImage();
                },
            });

            // add the button to the toolbar
            appendNode(exportButton, buttonGroup);

            // clone the toolbar array when returning to Pintura
            return [...toolbar];
        },
    });

    editor.on('process', (imageState) => {
        document.querySelector('img').src = URL.createObjectURL(
            imageState.dest
        );
    });
</script>