- Built-in toolbar items
- Add a custom toolbar item
- Show or hide a toolbar
- Show or hide a toolbar item
- Enable or disable a toolbar item
- Enable or disable a contextual toolbar item
- Customize contextual toolbar
- Add an additional contextual Toolbar item to text shape
- Toolbar created event
- Toolbar item clicked event
- Toolbar template
Toolbar in the Vue Image Editor component
26 Mar 202524 minutes to read
The toolbars in the Image Editor are a key component for interacting with and editing images. They provide a range of tools and options that can be customized to suit the needs and preferences. Add or remove items from the toolbar to create a personalized set of tools, or they can even create their own custom toolbar from scratch. This flexibility and customization allow them to create a unique image editing experience that is tailored to their specific needs and workflow.
In the Image Editor, the toolbar
property provides the ability to customize the toolbar by adding or removing items, as well as defining a completely custom toolbar. This feature is valuable for creating a personalized image editing experience that aligns with specific requirements and workflows.
Built-in toolbar items
Specifies the toolbar items to perform UI interactions. Refer to the built-in toolbar items for the default value.
- Open
- Undo
- Redo
- ZoomIn
- ZoomOut
- Crop
- RotateLeft
- RotateRight
- HorizontalFlip
- VerticalFlip
- Straightening
- Annotate
- Finetune
- Filter
- Frame
- Resize
- Redact
- Reset
- Save
Add a custom toolbar item
Users can define their own toolbars for an image editor by customizing the items or the entire toolbar. Users can achieve this by using the toolbar
property.
The built-in toolbar can be customized using the toolbar
property, so the specified toolbar items can be enabled in the Image Editor toolbar. And the contextual toolbar which is enabled while inserting annotations can also be customized in the toolbarUpdating
event.
<template>
<div>
<ejs-imageeditor id="image-editor" ref="imageEditorObj" height="350px" width="550px" :toolbar="toolbar"
:created="created" :toolbarItemClicked="toolbarItemClicked"></ejs-imageeditor>
</div>
</template>
<script setup>
import { ImageEditorComponent as EjsImageeditor } from "@syncfusion/ej2-vue-image-editor";
import { Browser } from "@syncfusion/ej2-base";
import { ref } from "vue";
const imageEditorObj = ref(null);
const toolbar = ['Crop', 'CustomSelection', 'SquareSelection', 'ZoomIn', 'ZoomOut', { text: 'Rotate' }];
const created = () => {
const imageEditor = imageEditorObj.value?.ej2Instances;
if (!imageEditor) return;
const imageUrl = Browser.isDevice
? "https://ej2.syncfusion.com/react/demos/src/image-editor/images/flower.png"
: "https://ej2.syncfusion.com/react/demos/src/image-editor/images/bridge.png";
imageEditor.open(imageUrl);
};
const toolbarItemClicked = (args) => {
if (args.item.text === 'Rotate') {
imageEditorObj.value?.ej2Instances.rotate(90);
}
};
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/material.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-lists/styles/material.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/material.css";
@import "../node_modules/@syncfusion/ej2-inputs/styles/material.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/material.css";
@import "../node_modules/@syncfusion/ej2-dropdowns/styles/material.css";
@import "../node_modules/@syncfusion/ej2-image-editor/styles/material.css";
#image-editor {
width: 550px !important;
height: 350px !important;
}
</style>
<template>
<div>
<ejs-imageeditor id="image-editor" ref="imageEditorObj" height="350px" width="550px" :toolbar="toolbar"
:created="onCreated" :toolbarItemClicked="toolbarItemClicked"></ejs-imageeditor>
</div>
</template>
<script>
import { ImageEditorComponent } from "@syncfusion/ej2-vue-image-editor";
import { Browser } from "@syncfusion/ej2-base";
export default {
name: "App",
components: {
"ejs-imageeditor": ImageEditorComponent,
},
data: function () {
return {
toolbar: ['Crop', 'CustomSelection', 'SquareSelection', 'ZoomIn', 'ZoomOut', { text: 'Rotate' }]
};
},
methods: {
onCreated() {
let imageEditor = this.$refs.imageEditorObj?.ej2Instances;
if (!imageEditor) return;
let imageUrl = Browser.isDevice
? 'https://ej2.syncfusion.com/react/demos/src/image-editor/images/flower.png'
: 'https://ej2.syncfusion.com/react/demos/src/image-editor/images/bridge.png';
imageEditor.open(imageUrl);
},
toolbarItemClicked: function (args) {
if (args.item.text === 'Rotate') {
this.$refs.imageEditorObj.ej2Instances.rotate(90);
}
},
},
}
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/material.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-lists/styles/material.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/material.css";
@import "../node_modules/@syncfusion/ej2-inputs/styles/material.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/material.css";
@import "../node_modules/@syncfusion/ej2-dropdowns/styles/material.css";
@import "../node_modules/@syncfusion/ej2-image-editor/styles/material.css";
#image-editor {
width: 550px !important;
height: 350px !important;
}
</style>
Show or hide a toolbar
The toolbar
property controls the visibility of the toolbar in the Image Editor. When the toolbar
property is set to an empty list, the toolbar is hidden. Conversely, if the toolbar
property contains a list of items, the toolbar is shown, displaying the specified items. This feature provides flexibility for users to personalize their image editing experience.
Here is an example of hiding the toolbar of the image editor using toolbar
property.
<template>
<div>
<ejs-imageeditor id="image-editor" ref="imageEditorObj" height="350px" width="550px" :created="created"
:toolbar="toolbar"></ejs-imageeditor>
</div>
</template>
<script setup>
import { ImageEditorComponent as EjsImageeditor } from "@syncfusion/ej2-vue-image-editor";
import { Browser } from "@syncfusion/ej2-base";
import { ref } from "vue";
const imageEditorObj = ref(null);
const toolbar = [];
const created = () => {
const imageEditor = imageEditorObj.value?.ej2Instances;
if (!imageEditor) return;
const imageUrl = Browser.isDevice
? "https://ej2.syncfusion.com/react/demos/src/image-editor/images/flower.png"
: "https://ej2.syncfusion.com/react/demos/src/image-editor/images/bridge.png";
imageEditor.open(imageUrl);
};
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/material.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-lists/styles/material.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/material.css";
@import "../node_modules/@syncfusion/ej2-inputs/styles/material.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/material.css";
@import "../node_modules/@syncfusion/ej2-dropdowns/styles/material.css";
@import "../node_modules/@syncfusion/ej2-image-editor/styles/material.css";
#image-editor {
width: 550px !important;
height: 350px !important;
}
</style>
<template>
<div>
<ejs-imageeditor id="image-editor" ref="imageEditorObj" height="350px" width="550px" :created="onCreated"
:toolbar="toolbar"></ejs-imageeditor>
</div>
</template>
<script>
import { ImageEditorComponent } from "@syncfusion/ej2-vue-image-editor";
import { Browser } from "@syncfusion/ej2-base";
export default {
name: "App",
components: {
"ejs-imageeditor": ImageEditorComponent
},
data: function () {
return {
toolbar: []
};
},
methods: {
onCreated() {
let imageEditor = this.$refs.imageEditorObj?.ej2Instances;
if (!imageEditor) return;
let imageUrl = Browser.isDevice
? 'https://ej2.syncfusion.com/react/demos/src/image-editor/images/flower.png'
: 'https://ej2.syncfusion.com/react/demos/src/image-editor/images/bridge.png';
imageEditor.open(imageUrl);
},
},
}
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/material.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-lists/styles/material.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/material.css";
@import "../node_modules/@syncfusion/ej2-inputs/styles/material.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/material.css";
@import "../node_modules/@syncfusion/ej2-dropdowns/styles/material.css";
@import "../node_modules/@syncfusion/ej2-image-editor/styles/material.css";
#image-editor {
width: 550px !important;
height: 350px !important;
}
</style>
Show or hide a toolbar item
The toolbar
property controls the visibility of the toolbar in the Image Editor. When the toolbar
property is set to an empty list, the toolbar is hidden. Conversely, if the toolbar
property contains a list of items, the toolbar is shown, displaying the specified items. This feature provides flexibility for users to personalize their image editing experience.
Here is an example of hiding the cropping and selection toolbar items using toolbar
property.
<template>
<div>
<ejs-imageeditor id="image-editor" ref="imageEditorObj" height="350px" width="550px" :created="created"
:toolbar="toolbar"></ejs-imageeditor>
</div>
</template>
<script setup>
import { ImageEditorComponent as EjsImageeditor } from "@syncfusion/ej2-vue-image-editor";
import { Browser } from "@syncfusion/ej2-base";
import { ref } from "vue";
const imageEditorObj = ref(null);
const toolbar = ['Annotate', 'Finetune', 'Filter', 'Confirm', 'Reset', 'Save', 'ZoomIn', 'ZoomOut'];
const created = () => {
const imageEditor = imageEditorObj.value?.ej2Instances;
if (!imageEditor) return;
const imageUrl = Browser.isDevice
? "https://ej2.syncfusion.com/react/demos/src/image-editor/images/flower.png"
: "https://ej2.syncfusion.com/react/demos/src/image-editor/images/bridge.png";
imageEditor.open(imageUrl);
};
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/material.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-lists/styles/material.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/material.css";
@import "../node_modules/@syncfusion/ej2-inputs/styles/material.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/material.css";
@import "../node_modules/@syncfusion/ej2-dropdowns/styles/material.css";
@import "../node_modules/@syncfusion/ej2-image-editor/styles/material.css";
#image-editor {
width: 550px !important;
height: 350px !important;
}
</style>
<template>
<div>
<ejs-imageeditor id="image-editor" ref="imageEditorObj" height="350px" width="550px" :created="onCreated"
:toolbar="toolbar"></ejs-imageeditor>
</div>
</template>
<script>
import { ImageEditorComponent } from "@syncfusion/ej2-vue-image-editor";
import { Browser } from "@syncfusion/ej2-base";
export default {
name: "App",
components: {
"ejs-imageeditor": ImageEditorComponent
},
data: function () {
return {
toolbar: ['Annotate', 'Finetune', 'Filter', 'Confirm', 'Reset', 'Save', 'ZoomIn', 'ZoomOut']
};
},
methods: {
onCreated() {
let imageEditor = this.$refs.imageEditorObj?.ej2Instances;
if (!imageEditor) return;
let imageUrl = Browser.isDevice
? 'https://ej2.syncfusion.com/react/demos/src/image-editor/images/flower.png'
: 'https://ej2.syncfusion.com/react/demos/src/image-editor/images/bridge.png';
imageEditor.open(imageUrl);
},
},
}
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/material.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-lists/styles/material.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/material.css";
@import "../node_modules/@syncfusion/ej2-inputs/styles/material.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/material.css";
@import "../node_modules/@syncfusion/ej2-dropdowns/styles/material.css";
@import "../node_modules/@syncfusion/ej2-image-editor/styles/material.css";
#image-editor {
width: 550px !important;
height: 350px !important;
}
</style>
Enable or disable a toolbar item
The toolbar
property is employed to enable or disable toolbar items in the Image Editor. By default, the toolbar
property includes the default toolbar items, and these items cannot be disabled. However, if you have defined custom toolbar items using the toolbarItemModel, you can enable or disable them by configuring their respective properties within the toolbar
property. This provides the flexibility to control the availability and functionality of custom toolbar items based on your specific requirements.
Here is an example of disabling the custom toolbar item using toolbar
property.
<template>
<div>
<ejs-imageeditor id="image-editor" ref="imageEditorObj" height="350px" width="550px" :created="onCreated"
:toolbar="toolbar" v-on:toolbarItemClicked="onToolbarItemClick">
</ejs-imageeditor>
</div>
</template>
<script setup>
import { ref } from 'vue';
import { ImageEditorComponent as EjsImageeditor } from '@syncfusion/ej2-vue-image-editor';
import { Browser } from '@syncfusion/ej2-base';
const imageEditorObj = ref(null);
const toolbar = ref([
{
id: 'rotate-left',
prefixIcon: 'e-icons e-anti-clock-wise',
tooltipText: 'Rotate Left',
align: 'Left',
},
{
id: 'rotate-right',
prefixIcon: 'e-icons e-clock-wise',
tooltipText: 'Rotate Right',
align: 'Left',
},
{
id: 'annotate',
prefixIcon: 'e-icons e-annotation',
tooltipText: 'Annotate',
align: 'Center',
disabled: true,
},
{
id: 'save',
prefixIcon: 'e-icons e-save',
tooltipText: 'Save',
align: 'Right',
},
]);
const onCreated = () => {
let imageEditor = imageEditorObj.value?.ej2Instances;
if (!imageEditor) return;
let imageUrl = Browser.isDevice
? 'https://ej2.syncfusion.com/react/demos/src/image-editor/images/flower.png'
: 'https://ej2.syncfusion.com/react/demos/src/image-editor/images/bridge.png';
imageEditor.open(imageUrl);
};
const onToolbarItemClick = (args) => {
let imageEditor = imageEditorObj.value?.ej2Instances;
if (!imageEditor) return;
if (args.item.id === 'rotate-left') {
imageEditor.rotate(-90);
} else if (args.item.id === 'rotate-right') {
imageEditor.rotate(90);
} else if (args.item.id === 'save') {
imageEditor.export('PNG');
}
};
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/material.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-lists/styles/material.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/material.css";
@import "../node_modules/@syncfusion/ej2-inputs/styles/material.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/material.css";
@import "../node_modules/@syncfusion/ej2-dropdowns/styles/material.css";
@import "../node_modules/@syncfusion/ej2-image-editor/styles/material.css";
#image-editor {
width: 550px !important;
height: 350px !important;
}
</style>
<template>
<div>
<ejs-imageeditor id="image-editor" ref="imageEditorObj" height="350px" width="550px" :created="onCreated"
:toolbar="toolbar" v-on:toolbarItemClicked="onToolbarItemClick">
</ejs-imageeditor>
</div>
</template>
<script>
import { ImageEditorComponent } from '@syncfusion/ej2-vue-image-editor';
import { Browser } from '@syncfusion/ej2-base';
export default {
name: 'App',
components: {
'ejs-imageeditor': ImageEditorComponent,
},
data() {
return {
toolbar: [
{
id: 'rotate-left',
prefixIcon: 'e-icons e-anti-clock-wise',
tooltipText: 'Rotate Left',
align: 'Left',
},
{
id: 'rotate-right',
prefixIcon: 'e-icons e-clock-wise',
tooltipText: 'Rotate Right',
align: 'Left',
},
{
id: 'annotate',
prefixIcon: 'e-icons e-annotation',
tooltipText: 'Annotate',
align: 'Center',
disabled: true,
},
{
id: 'save',
prefixIcon: 'e-icons e-save',
tooltipText: 'Save',
align: 'Right',
},
],
};
},
methods: {
onCreated() {
let imageEditor = this.$refs.imageEditorObj?.ej2Instances;
if (!imageEditor) return;
let imageUrl = Browser.isDevice
? 'https://ej2.syncfusion.com/react/demos/src/image-editor/images/flower.png'
: 'https://ej2.syncfusion.com/react/demos/src/image-editor/images/bridge.png';
imageEditor.open(imageUrl);
},
onToolbarItemClick(args) {
let imageEditor = this.$refs.imageEditorObj?.ej2Instances;
if (!imageEditor) return;
if (args.item.id === 'rotate-left') {
imageEditor.rotate(-90);
} else if (args.item.id === 'rotate-right') {
imageEditor.rotate(90);
} else if (args.item.id === 'save') {
imageEditor.export('PNG');
}
},
},
};
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/material.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-lists/styles/material.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/material.css";
@import "../node_modules/@syncfusion/ej2-inputs/styles/material.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/material.css";
@import "../node_modules/@syncfusion/ej2-dropdowns/styles/material.css";
@import "../node_modules/@syncfusion/ej2-image-editor/styles/material.css";
#image-editor {
width: 550px !important;
height: 350px !important;
}
</style>
Enable or disable a contextual toolbar item
The toolbarItems property in the toolbarEventArgs is used to enable or disable contextual toolbar items in the Image Editor. To enable or disable the default toolbar items, you can accomplish this by setting the Disabled property to true in the ImageEditorToolbarItemModel within the ToolbarItems property. This allows you to selectively enable or disable specific default toolbar items based on your requirements, providing a customized toolbar experience in the Image Editor.
Customize contextual toolbar
The toolbarUpdating
event is triggered when inserting or selecting annotations, which opens the contextual toolbar in the Image Editor. Within this event, the toolbarItems
property in the ToolbarEventArgs
is utilized to add or remove contextual toolbar items.
In the following example, the contextual toolbar for freehand drawing will be rendered with only the stroke color, while the stroke width, remove, and separator options are excluded using the toolbarUpdating
event.
<template>
<div>
<ejs-imageeditor id="image-editor" ref="imageEditorObj" height="350px" width="550px" :created="created"
:toolbarUpdating="toolbarUpdating"></ejs-imageeditor>
</div>
</template>
<script setup>
import { ImageEditorComponent as EjsImageeditor } from "@syncfusion/ej2-vue-image-editor";
import { Browser } from "@syncfusion/ej2-base";
import { ref } from 'vue';
const imageEditorObj = ref(null);
const created = () => {
const imageEditor = imageEditorObj.value?.ej2Instances;
if (!imageEditor) return;
const imageUrl = Browser.isDevice
? "https://ej2.syncfusion.com/react/demos/src/image-editor/images/flower.png"
: "https://ej2.syncfusion.com/react/demos/src/image-editor/images/bridge.png";
imageEditor.open(imageUrl);
};
const toolbarUpdating = (args) => {
if (args.toolbarType === 'pen') {
args.toolbarItems.forEach(item => {
if (item.align === 'Center' && (item.tooltipText === 'Stroke Width' || item.tooltipText === 'Remove' || item.type === 'Separator')) {
item.visible = false;
}
});
}
};
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/material.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-lists/styles/material.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/material.css";
@import "../node_modules/@syncfusion/ej2-inputs/styles/material.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/material.css";
@import "../node_modules/@syncfusion/ej2-dropdowns/styles/material.css";
@import "../node_modules/@syncfusion/ej2-image-editor/styles/material.css";
#image-editor {
width: 550px !important;
height: 350px !important;
}
</style>
<template>
<div>
<ejs-imageeditor id="image-editor" ref="imageEditorObj" height="350px" width="550px" :created="onCreated"
:toolbarUpdating="toolbarUpdating"></ejs-imageeditor>
</div>
</template>
<script>
import { ImageEditorComponent } from "@syncfusion/ej2-vue-image-editor";
import { Browser } from "@syncfusion/ej2-base";
export default {
name: "App",
components: {
"ejs-imageeditor": ImageEditorComponent
},
data: function () {
return {};
},
methods: {
onCreated() {
let imageEditor = this.$refs.imageEditorObj?.ej2Instances;
if (!imageEditor) return;
let imageUrl = Browser.isDevice
? 'https://ej2.syncfusion.com/react/demos/src/image-editor/images/flower.png'
: 'https://ej2.syncfusion.com/react/demos/src/image-editor/images/bridge.png';
imageEditor.open(imageUrl);
},
toolbarUpdating: function (args) {
if (args.toolbarType === 'pen') {
args.toolbarItems.forEach(item => {
if (item.align === 'Center' && (item.tooltipText === 'Stroke Width' || item.tooltipText === 'Remove' || item.type === 'Separator')) {
item.visible = false;
}
});
}
}
}
}
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/material.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-lists/styles/material.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/material.css";
@import "../node_modules/@syncfusion/ej2-inputs/styles/material.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/material.css";
@import "../node_modules/@syncfusion/ej2-dropdowns/styles/material.css";
@import "../node_modules/@syncfusion/ej2-image-editor/styles/material.css";
#image-editor {
width: 550px !important;
height: 350px !important;
}
</style>
Add an additional contextual Toolbar item to text shape
The contextual toolbar that appears when inserting annotations in the Image Editor is customizable using the toolbarUpdating
event. This event is triggered when the contextual toolbar is rendered, allowing you to modify its contents. To add additional toolbar items to the contextual toolbar, you can access the toolbarItems
property of the object within the event handler. By adding or removing items from the toolbarItems
property based on the Item property, you can customize the options available in the contextual toolbar according to your needs. This gives you the ability to extend the functionality of the contextual toolbar and provide additional tools and options for working with inserted annotations.
Here is an example of adding the custom toolbar item to the contextual toolbar.
<template>
<div>
<ejs-imageeditor id="image-editor" ref="imageEditorObj" height="350px" width="550px"
:toolbarUpdating="toolbarUpdating" :created="created"></ejs-imageeditor>
</div>
</template>
<script setup>
import { ImageEditorComponent as EjsImageeditor } from "@syncfusion/ej2-vue-image-editor";
import { Browser } from "@syncfusion/ej2-base";
import { ref } from "vue";
const imageEditorObj = ref(null);
const created = () => {
const imageEditor = imageEditorObj.value?.ej2Instances;
if (!imageEditor) return;
let imageUrl = Browser.isDevice
? "https://ej2.syncfusion.com/react/demos/src/image-editor/images/flower.png"
: "https://ej2.syncfusion.com/react/demos/src/image-editor/images/bridge.png";
imageEditor.open(imageUrl);
};
const toolbarUpdating = (args) => {
if (args.toolbarType === 'text') {
args.toolbarItems.push({ text: 'custom' })
}
};
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/material.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-lists/styles/material.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/material.css";
@import "../node_modules/@syncfusion/ej2-inputs/styles/material.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/material.css";
@import "../node_modules/@syncfusion/ej2-dropdowns/styles/material.css";
@import "../node_modules/@syncfusion/ej2-image-editor/styles/material.css";
#image-editor {
width: 550px !important;
height: 350px !important;
}
</style>
<template>
<div>
<ejs-imageeditor id="image-editor" ref="imageEditorObj" height="350px" width="550px"
:toolbarUpdating="toolbarUpdating" :created="created"></ejs-imageeditor>
</div>
</template>
<script>
import { ImageEditorComponent } from "@syncfusion/ej2-vue-image-editor";
import { Browser } from "@syncfusion/ej2-base";
export default {
name: "App",
components: {
"ejs-imageeditor": ImageEditorComponent
},
data: function () {
return {};
},
methods: {
created() {
let imageEditor = this.$refs.imageEditorObj?.ej2Instances;
if (!imageEditor) return;
let imageUrl = Browser.isDevice
? 'https://ej2.syncfusion.com/react/demos/src/image-editor/images/flower.png'
: 'https://ej2.syncfusion.com/react/demos/src/image-editor/images/bridge.png';
imageEditor.open(imageUrl);
},
toolbarUpdating: function (args) {
if (args.toolbarType === 'text') {
args.toolbarItems.push({ text: 'custom' })
}
}
}
}
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/material.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-lists/styles/material.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/material.css";
@import "../node_modules/@syncfusion/ej2-inputs/styles/material.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/material.css";
@import "../node_modules/@syncfusion/ej2-dropdowns/styles/material.css";
@import "../node_modules/@syncfusion/ej2-image-editor/styles/material.css";
#image-editor {
width: 550px !important;
height: 350px !important;
}
</style>
Toolbar created event
The toolbarCreated
event is triggered after the toolbar is created in the Image Editor. This event can be useful when you need to perform any actions or make modifications to the toolbar once it is fully initialized and ready for interaction. By subscribing to the toolbarCreated
event, you can access the toolbar object and perform tasks such as adding event handlers, customizing the appearance, or configuring additional functionality.
Toolbar item clicked event
The toolbarItemClicked
event is triggered when a toolbar item is clicked in the Image Editor. This event is particularly useful when you have added custom options to both the main toolbar and contextual toolbar, as it allows you to capture the user’s interaction with those custom options. By subscribing to the toolbarItemClicked
event, you can execute specific actions or handle logic based on the toolbar item that was clicked.
<template>
<div>
<ejs-imageeditor id="image-editor" ref="imageEditorObj" height="350px" width="550px" :created="created"
:toolbarItemClicked="toolbarItemClicked" :toolbar="toolbar"></ejs-imageeditor>
</div>
</template>
<script setup>
import { ImageEditorComponent as EjsImageeditor } from "@syncfusion/ej2-vue-image-editor";
import { Browser } from "@syncfusion/ej2-base";
import { ref } from 'vue';
const imageEditorObj = ref(null);
const toolbar = [{ text: 'Custom' }];
const created = () => {
const imageEditor = imageEditorObj.value?.ej2Instances;
if (!imageEditor) return;
const imageUrl = Browser.isDevice
? "https://ej2.syncfusion.com/react/demos/src/image-editor/images/flower.png"
: "https://ej2.syncfusion.com/react/demos/src/image-editor/images/bridge.png";
imageEditor.open(imageUrl);
};
const toolbarItemClicked = (args) => {
if (args.item.text === 'Custom') {
imageEditorObj.value.rotate(90);
}
};
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/material.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-lists/styles/material.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/material.css";
@import "../node_modules/@syncfusion/ej2-inputs/styles/material.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/material.css";
@import "../node_modules/@syncfusion/ej2-dropdowns/styles/material.css";
@import "../node_modules/@syncfusion/ej2-image-editor/styles/material.css";
#image-editor {
width: 550px !important;
height: 350px !important;
}
</style>
<template>
<div>
<ejs-imageeditor id="image-editor" ref="imageEditorObj" height="350px" width="550px"
:toolbarItemClicked="toolbarItemClicked" :toolbar="toolbar" :created="onCreated"></ejs-imageeditor>
</div>
</template>
<script>
import { ImageEditorComponent } from "@syncfusion/ej2-vue-image-editor";
import { Browser } from "@syncfusion/ej2-base";
export default {
name: "App",
components: {
"ejs-imageeditor": ImageEditorComponent
},
data: function () {
return {
toolbar: [{ text: 'Custom' }]
};
},
methods: {
onCreated() {
let imageEditor = this.$refs.imageEditorObj?.ej2Instances;
if (!imageEditor) return;
let imageUrl = Browser.isDevice
? 'https://ej2.syncfusion.com/react/demos/src/image-editor/images/flower.png'
: 'https://ej2.syncfusion.com/react/demos/src/image-editor/images/bridge.png';
imageEditor.open(imageUrl);
},
toolbarItemClicked: function (args) {
if (args.item.text === 'Custom') {
this.$refs.imageEditorObj.rotate(90);
}
}
}
}
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/material.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-lists/styles/material.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/material.css";
@import "../node_modules/@syncfusion/ej2-inputs/styles/material.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/material.css";
@import "../node_modules/@syncfusion/ej2-dropdowns/styles/material.css";
@import "../node_modules/@syncfusion/ej2-image-editor/styles/material.css";
#image-editor {
width: 550px !important;
height: 350px !important;
}
</style>
Toolbar template
The toolbarTemplate
property in the Image Editor provides the capability to fully customize the toolbar by supplying a custom template. This feature is valuable when you want to create a distinct and personalized image editing experience that goes beyond the default toolbar or the customizable toolbar options offered by the Image Editor. By defining a custom template for the toolbar, you have complete control over its layout, appearance, and functionality. This empowers you to design a unique and tailored toolbar that aligns perfectly with your specific requirements and desired user experience.
Here is an example of using toolbarTemplate
to render only the button to toggle the freehand draw option.
The toolbar of the Image Editor can be replaced with the user specific UI using the toolbarTemplate
property.
<template>
<div>
<ejs-imageeditor id="image-editor" ref="imageEditorObj" height="350px" width="550px"
:toolbarTemplate="customToolbar" :created="onCreated"></ejs-imageeditor>
</div>
</template>
<script setup>
import { ref, nextTick } from "vue";
import { ImageEditorComponent as EjsImageeditor } from "@syncfusion/ej2-vue-image-editor";
import { Browser } from "@syncfusion/ej2-base";
const imageEditorObj = ref(null);
const customToolbar = `
<div class="e-toolbar">
<button id="freeHandDrawButton" class="e-btn e-primary">Freehand Draw</button>
</div>
`;
const enableFreeHandDraw = () => {
const imageEditor = imageEditorObj.value?.ej2Instances;
if (imageEditor) {
imageEditor.freeHandDraw(true);
}
};
const onCreated = () => {
const imageEditor = imageEditorObj.value?.ej2Instances;
if (!imageEditor) return;
const imageUrl = Browser.isDevice
? "https://ej2.syncfusion.com/react/demos/src/image-editor/images/flower.png"
: "https://ej2.syncfusion.com/react/demos/src/image-editor/images/bridge.png";
imageEditor.open(imageUrl);
nextTick(() => {
const button = document.getElementById("freeHandDrawButton");
if (button) {
button.addEventListener("click", enableFreeHandDraw);
}
});
};
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/material.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-lists/styles/material.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/material.css";
@import "../node_modules/@syncfusion/ej2-inputs/styles/material.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/material.css";
@import "../node_modules/@syncfusion/ej2-dropdowns/styles/material.css";
@import "../node_modules/@syncfusion/ej2-image-editor/styles/material.css";
#image-editor {
width: 550px !important;
height: 350px !important;
}
</style>
<template>
<div>
<ejs-imageeditor id="image-editor" ref="imageEditorObj" height="350px" width="550px"
:toolbarTemplate="customToolbar" @created="onCreated"></ejs-imageeditor>
</div>
</template>
<script>
import { ImageEditorComponent as EjsImageeditor } from "@syncfusion/ej2-vue-image-editor";
import { Browser } from "@syncfusion/ej2-base";
export default {
components: {
EjsImageeditor,
},
data() {
return {
imageEditorObj: null,
customToolbar: `
<div class="e-toolbar">
<button id="freeHandDrawButton" class="e-btn e-primary">Freehand Draw</button>
</div>
`,
};
},
methods: {
enableFreeHandDraw() {
const imageEditor = this.imageEditorObj?.ej2Instances;
if (imageEditor) {
imageEditor.freeHandDraw(true);
}
},
onCreated() {
const imageEditor = this.$refs.imageEditorObj?.ej2Instances;
if (!imageEditor) return;
this.imageEditorObj = this.$refs.imageEditorObj;
const imageUrl = Browser.isDevice
? "https://ej2.syncfusion.com/react/demos/src/image-editor/images/flower.png"
: "https://ej2.syncfusion.com/react/demos/src/image-editor/images/bridge.png";
imageEditor.open(imageUrl);
this.$nextTick(() => {
const button = document.getElementById("freeHandDrawButton");
if (button) {
button.addEventListener("click", this.enableFreeHandDraw);
}
});
},
},
};
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/material.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-lists/styles/material.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/material.css";
@import "../node_modules/@syncfusion/ej2-inputs/styles/material.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/material.css";
@import "../node_modules/@syncfusion/ej2-dropdowns/styles/material.css";
@import "../node_modules/@syncfusion/ej2-image-editor/styles/material.css";
#image-editor {
width: 550px !important;
height: 350px !important;
}
</style>