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>
import '@pqina/pintura/pintura.css';
import './App.css';
import { useRef, useState } from 'react';
import { PinturaEditor } from '@pqina/react-pintura';
import {
processImage,
getEditorDefaults,
createNode,
appendNode,
findNode,
} from '@pqina/pintura';
const editorDefaults = getEditorDefaults();
function App() {
const [editorResult, setEditorResult] = useState(undefined);
const editorRef = useRef(null);
const 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
editorRef.current.editor.processImage();
},
});
// add the button to the toolbar
appendNode(exportButton, buttonGroup);
// clone the toolbar array when returning to Pintura
return [...toolbar];
};
const handleEditorProcess = (imageState) => {
setEditorResult(URL.createObjectURL(imageState.dest));
};
return (
<div className="App">
{editorResult && <img alt="" src={editorResult} />}
<PinturaEditor
ref={editorRef}
{...editorDefaults}
src={'image.jpeg'}
// This removes the default done button
enableButtonExport={false}
willRenderToolbar={willRenderToolbar}
onProcess={handleEditorProcess}
/>
</div>
);
}
export default App;
.pintura-editor {
height: 600px;
}
<template>
<div>
<img v-if="editorResult" alt="" :src="editorResult" />
<PinturaEditor
ref="editor"
v-bind="editorDefaults"
src="image.jpeg"
:enableButtonExport="false"
:willRenderToolbar="willRenderToolbar"
v-on:pintura:process="handleEditorProcess($event)"
/>
</div>
</template>
<script>
import { PinturaEditor } from '@pqina/vue-pintura';
import {
processImage,
getEditorDefaults,
createNode,
appendNode,
findNode,
} from '@pqina/pintura';
export default {
name: 'App',
components: {
PinturaEditor,
},
data() {
return {
editorResult: undefined,
editorDefaults: getEditorDefaults(),
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
this.$refs.editor.editor.processImage();
},
});
// add the button to the toolbar
appendNode(exportButton, buttonGroup);
// clone the toolbar array when returning to Pintura
return [...toolbar];
},
};
},
methods: {
handleEditorProcess: function (imageState) {
this.editorResult = URL.createObjectURL(imageState.dest);
},
},
};
</script>
<style>
@import '@pqina/pintura/pintura.css';
.pintura-editor {
height: 600px;
}
</style>
<script>
import { PinturaEditor } from '@pqina/svelte-pintura';
import {
processImage,
getEditorDefaults,
createNode,
appendNode,
findNode,
} from '@pqina/pintura';
import '@pqina/pintura/pintura.css';
let editorResult = undefined;
let editorDefaults = getEditorDefaults();
let editor;
const 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];
};
const handleEditorProcess = (event) => {
const imageState = event.detail;
editorResult = URL.createObjectURL(imageState.dest);
};
</script>
<div>
{#if editorResult} <img alt="" src={editorResult} /> {/if}
<PinturaEditor
bind:this={editor}
{...editorDefaults}
src={'image.jpeg'}
enableButtonExport={/* This removes the default done button */
false}
{willRenderToolbar}
on:process={handleEditorProcess}
/>
</div>
<style>
div :global(.pintura-editor) {
height: 600px;
}
</style>
import { Component, ViewChild } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
import {
processImage,
getEditorDefaults,
createNode,
appendNode,
findNode,
PinturaNode,
} from '@pqina/pintura';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent {
constructor(private domSanitizer: DomSanitizer) {}
@ViewChild('editor') editor?: any;
editorResult?: string = undefined;
editorDefaults: any = getEditorDefaults();
willRenderToolbar = (toolbar: PinturaNode[]): PinturaNode[] => {
// 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
this.editor.editor.processImage();
},
});
// add the button to the toolbar
appendNode(exportButton, buttonGroup);
// clone the toolbar array when returning to Pintura
return [...toolbar];
};
handleEditorProcess(imageState: any): void {
this.editorResult = <string>(
this.domSanitizer.bypassSecurityTrustResourceUrl(
URL.createObjectURL(imageState.dest)
)
);
}
}
<img *ngIf="editorResult" [src]="editorResult" alt="" />
<pintura-editor
#editor
[options]="editorDefaults"
src="image.jpeg"
[enableButtonExport]="false"
[willRenderToolbar]="willRenderToolbar"
(process)="handleEditorProcess($event)"
></pintura-editor>
::ng-deep .pintura-editor {
height: 600px;
}
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { AngularPinturaModule } from '@pqina/angular-pintura';
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule, AngularPinturaModule],
exports: [AppComponent],
providers: [],
bootstrap: [AppComponent],
})
export class AppModule {}
<!DOCTYPE html>
<head>
<link rel="stylesheet" href="./pintura/pintura.css" />
</head>
<script src="./jquery.js"></script>
<script src="./jquery-pintura/useEditorWithJQuery-iife.js"></script>
<script src="./pintura/pintura-iife.js"></script>
<img src="" alt="" />
<style>
.pintura-editor {
height: 600px;
}
</style>
<div id="editor"></div>
<script>
useEditorWithJQuery(jQuery, pintura);
$(function () {
var { processImage, createNode, appendNode, findNode } = $.fn.pintura;
var editor = $('#editor').pinturaDefault({
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).pintura('processImage');
},
});
// add the button to the toolbar
appendNode(exportButton, buttonGroup);
// clone the toolbar array when returning to Pintura
return [...toolbar];
},
});
editor.on('pintura:process', function (event) {
const imageState = event.detail;
$('img').attr('src', URL.createObjectURL(imageState.dest));
});
});
</script>