Transform in the vue Image Editor component
11 Jun 202422 minutes to read
The Image Editor provides a range of transformation options for manipulating both the image and its annotations. These options include rotation, flipping, zooming, and panning. These transformations offer flexibility in adjusting the image and enhancing its visual appearance.
Rotate an image
The Image Editor allows to rotate the image and its annotations by a specific number of degrees clockwise or anti-clockwise using rotate
method. This method takes a single parameter: the angle of rotation in degrees. A positive value will rotate the image clockwise, while a negative value will rotate it anti-clockwise.
Here is an example of rotating an image in a button click event.
<template>
<div>
<ejs-imageeditor id="image-editor" ref="imageEditorObj" height="350px" width="550px" :toolbar="toolbar" :created="created"></ejs-imageeditor>
<ejs-button cssClass="e-img-button" :isPrimary="true" v-on:click="btnClick">Rotate</ejs-button>
</div>
</template>
<script setup>
import { ImageEditorComponent as EjsImageeditor } from "@syncfusion/ej2-vue-image-editor";
import { ButtonComponent as EjsButton} from '@syncfusion/ej2-vue-buttons';
import { Browser } from "@syncfusion/ej2-base";
import { ref } from "vue";
const imageEditorObj = ref(null);
const toolbar = [];
const created = () => {
if (Browser.isDevice) {
imageEditorObj.value.open('flower.png');
} else {
imageEditorObj.value.open('bridge.png');
}
};
const btnClick = () => {
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"></ejs-imageeditor>
<ejs-button cssClass="e-img-button" :isPrimary="true" v-on:click="btnClick">Rotate</ejs-button>
</div>
</template>
<script>
import { ImageEditorComponent as EjsImageeditor } from "@syncfusion/ej2-vue-image-editor";
import { ButtonComponent } from '@syncfusion/ej2-vue-buttons';
import { Browser } from "@syncfusion/ej2-base";
export default {
name: "App",
components: {
"ejs-imageeditor":ImageeditorComponent,
"ejs-button":ButtonComponent
},
data: function() {
return {
toolbar: []
};
},
methods: {
btnClick: function() {
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>
Flip an image
The Image Editor provides the flip
method, which allows you to flip both the image and its annotations either horizontally or vertically. This method takes a single parameter of type ImageEditorDirection, which specifies the direction in which the flip operation should be applied.
The Direction
parameter accepts two values: ‘Horizontal’ and ‘Vertical’. When you choose ‘Horizontal’, the image and annotations will be flipped along the horizontal axis, resulting in a mirror effect. On the other hand, selecting ‘Vertical’ will flip them along the vertical axis, producing a vertical mirror effect.
Here is an example of flipping an image in a button click event.
<template>
<div>
<ejs-imageeditor id="image-editor" ref="imageEditorObj" height="350px" width="550px" :toolbar="toolbar" :created="created"></ejs-imageeditor>
<ejs-button cssClass="e-img-button" :isPrimary="true" v-on:click="btnClick">Flip</ejs-button>
</div>
</template>
<script setup>
import { ImageEditorComponent as EjsImageeditor} from "@syncfusion/ej2-vue-image-editor";
import { ButtonComponent as EjsButton} from '@syncfusion/ej2-vue-buttons';
import { Browser } from "@syncfusion/ej2-base";
import { ref } from "vue";
const imageEditorObj = ref(null);
const toolbar = [];
const created = () => {
if (Browser.isDevice) {
imageEditorObj.value.open('flower.png');
} else {
imageEditorObj.value.open('bridge.png');
}
};
const btnClick = () => {
imageEditorObj.value.ej2Instances.flip("Horizontal"); // Horizontal flip
};
</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" ></ejs-imageeditor>
<ejs-button cssClass="e-img-button" :isPrimary="true" v-on:click="btnClick">Flip</ejs-button>
</div>
</template>
<script>
import { ImageEditorComponent } from "@syncfusion/ej2-vue-image-editor";
import { ButtonComponent } from '@syncfusion/ej2-vue-buttons';
import { Browser } from "@syncfusion/ej2-base";
export default {
name: "App",
components: {
"ejs-imageeditor":ImageEditorComponent,
"ejs-button":ButtonComponent
},
data: function() {
return {
toolbar: []
};
},
methods: {
btnClick: function() {
this.$refs.imageEditorObj.ej2Instances.flip("Horizontal"); // Horizontal flip
}
}
}
</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>
Zoom in or out an image
The Image Editor allows to magnify an image using the zoom
method. This method allows one to zoom in and out of the image and provides a more detailed view of the image’s hidden areas. This method takes two parameters to perform zooming.
-
zoomFactor - Specifies a value to controlling the level of magnification applied to the image.
-
zoomPoint - Specifies x and y coordinates of a point as ImageEditorPoint on image to perform zooming.
Here is an example of zooming an image in a button click event.
<template>
<div>
<ejs-imageeditor id="image-editor" ref="imageEditorObj" height="350px" :created="created" width="550px" :zoomSettings="zoomSettings" :toolbar="toolbar"></ejs-imageeditor>
<ejs-button cssClass="e-img-button" :isPrimary="true" v-on:click="btn1Click">Zoom in</ejs-button>
<ejs-button cssClass="e-img-button" :isPrimary="true" v-on:click="btn2Click">Zoom out</ejs-button>
</div>
</template>
<script setup>
import { ImageEditorComponent as EjsImageeditor} from "@syncfusion/ej2-vue-image-editor";
import { ButtonComponent as EjsButton } from '@syncfusion/ej2-vue-buttons';
import { Browser } from "@syncfusion/ej2-base";
import { ref } from 'vue';
const imageEditorObj = ref(null);
const toolbar = [];
const zoomSettings = {maxZoomFactor: 30, minZoomFactor: 0.1};
let zoomLevel = 1;
const created = () => {
if (Browser.isDevice) {
imageEditorObj.value.open('flower.png');
} else {
imageEditorObj.value.open('bridge.png');
}
};
const btn1Click = () => {
if (zoomLevel < 1) {
zoomLevel += 0.1;
} else {
zoomLevel += 1;
}
if (zoomLevel > imageEditorObj.value.zoomSettings.maxZoomFactor) {
zoomLevel = imageEditorObj.value.zoomSettings.maxZoomFactor;
}
imageEditorObj.value.ej2Instances.zoom(zoomLevel); // Zoom in
};
const btn2Click = () => {
if (zoomLevel <= 1) {
zoomLevel -= 0.1;
} else {
zoomLevel -= 1;
}
if (zoomLevel < imageEditorObj.value.zoomSettings.minZoomFactor) {
zoomLevel = imageEditorObj.value.zoomSettings.minZoomFactor;
}
imageEditorObj.value.ej2Instances.zoom(zoomLevel); // Zoom out
};
</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" :zoomSettings="zoomSettings" :toolbar="toolbar"></ejs-imageeditor>
<ejs-button cssClass="e-img-button" :isPrimary="true" v-on:click="btn1Click">Zoom in</ejs-button>
<ejs-button cssClass="e-img-button" :isPrimary="true" v-on:click="btn2Click">Zoom out</ejs-button>
</div>
</template>
<script>
import { ImageEditorComponent } from "@syncfusion/ej2-vue-image-editor";
import { ButtonComponent } from '@syncfusion/ej2-vue-buttons';
import { Browser } from "@syncfusion/ej2-base";
export default {
name: "App",
components: {
"ejs-imageeditor":ImageEditorComponent,
"ejs-button":ButtonComponent
},
data: function() {
return {
toolbar: [],
zoomSettings: {maxZoomFactor: 30, minZoomFactor: 0.1},
zoomLevel: 1
};
},
methods: {
btn1Click: function() {
if (this.zoomLevel < 1) {
this.zoomLevel += 0.1;
} else {
this.zoomLevel += 1;
}
if (this.zoomLevel > this.$refs.imageEditorObj.zoomSettings.maxZoomFactor) {
this.zoomLevel = this.$refs.imageEditorObj.zoomSettings.maxZoomFactor;
}
this.$refs.imageEditorObj.ej2Instances.zoom(this.zoomLevel); // Zoom in
},
btn2Click: function() {
if (this.zoomLevel <= 1) {
this.zoomLevel -= 0.1;
} else {
this.zoomLevel -= 1;
}
if (this.zoomLevel < this.$refs.imageEditorObj.zoomSettings.minZoomFactor) {
this.zoomLevel = this.$refs.imageEditorObj.zoomSettings.minZoomFactor;
}
this.$refs.imageEditorObj.ej2Instances.zoom(this.zoomLevel); // Zoom out
}
}
}
</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>
Maximum and Minimum zoom level
The maxZoomFactor
property is a useful feature in the Image Editor that allows you to define the maximum level of zoom permitted for an image. This property sets a limit on how much the image can be magnified, preventing excessive zooming that may result in a loss of image quality or visibility.
By default, the minZoomFactor
value is set to 10, meaning that the image can be zoomed in up to 10 times its original size. This ensures that the zooming functionality remains within reasonable bounds and maintains the integrity of the image.
The maxZoomFactor
property allows you to specify the minimum level of zoom that is allowed for an image. By setting this property, you can prevent the image from being zoomed out beyond a certain point, ensuring that it remains visible and usable even at the smallest zoom level.
By default, the maxZoomFactor
value is set to 0.1, meaning that the image can be zoomed out up to 10 times its original size.
Here is an example of specifying minZoomFactor
and maxZoomFactor
property in zoomSettings
options in an image editor.
Panning an image
The Image Editor allows to pan an image when the image exceeds the canvas size or selection range. When zooming in on an image or applying a selection for cropping, it is common for the image to exceed the size of the canvas or exceed the selection range. So, the panning is used to view the entire image, by clicking on the canvas and dragging it in the direction they want to move.
Panning event
The panning
event is activated when the user begins dragging the image within the canvas. This event provide an opportunity to perform specific actions, like adjusting the position of an image, in response to the gesture of panning. And these event uses panEventArgs
to handle the panning action when the user starts dragging the image.
The parameter available in the panEventArgs
events are,
-
PanEventArgs.startPoint - The x and y coordinates as ImageEditorPoint for the start point.
-
PanEventArgs.endpoint - The x and y coordinates as ImageEditorPoint for the end point.
-
PanEventArgs.cancel – Specifies the boolean value to cancel the panning action.
<template>
<div>
<ejs-imageeditor id="image-editor" ref="imageEditorObj" height="350px" width="550px" :created="created" :toolbar="toolbar"></ejs-imageeditor>
<ejs-button cssClass="e-img-button" :isPrimary="true" v-on:click="btnClick">Zoom & Pan</ejs-button>
</div>
</template>
<script setup>
import { ImageEditorComponent as EjsImageeditor} from "@syncfusion/ej2-vue-image-editor";
import { ButtonComponent as EjsButton } from '@syncfusion/ej2-vue-buttons';
import { Browser } from "@syncfusion/ej2-base";
import { ref } from 'vue';
const imageEditorObj = ref(null);
const toolbar = [];
const zoomLevel = 1;
const created = () => {
if (Browser.isDevice) {
imageEditorObj.value.open('flower.png');
} else {
imageEditorObj.value.open('bridge.png');
}
};
const btnClick = () => {
imageEditorObj.value.ej2Instances.zoom(zoomLevel); // Zoom in
imageEditorObj.value.ej2Instances.pan(true);
};
</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"></ejs-imageeditor>
<ejs-button cssClass="e-img-button" :isPrimary="true" v-on:click="btnClick">Zoom & Pan</ejs-button>
</div>
</template>
<script>
import { ImageEditorComponent } from "@syncfusion/ej2-vue-image-editor";
import { ButtonComponent } from '@syncfusion/ej2-vue-buttons';
import { Browser } from "@syncfusion/ej2-base";
export default {
name: "App",
components: {
"ejs-imageeditor":ImageEditorComponent,
"ejs-button":ButtonComponent
},
data: function() {
return {
toolbar: [],
zoomLevel: 1
};
},
methods: {
btnClick: function() {
this.$refs.imageEditorObj.ej2Instances.zoom(this.zoomLevel); // Zoom in
this.$refs.imageEditorObj.ej2Instances.pan(true);
}
}
}
</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>
Zooming event
The zooming
event is triggered when performing zooming the image. This event can be used to perform certain actions, such as updating the position of the image. This event is passed an object that contains information about the zooming event, such as the amount of zooming performed. And this event uses ZoomEventArgs
to handle the zooming action in the image.
The parameter available in the Zooming event is,
-
ZoomEventArgs.zoomPoint - The x and y coordinates as ImageEditorPoint for the zoom point.
-
ZoomEventArgs.previousZoomFactor - The previous zoom factor applied in the image editor.
-
ZoomEventArgs.currentZoomFactor - The current zoom factor to be applied in the image editor.
-
ZoomEventArgs.cancel – Specify a boolean value to cancel the zooming action.
-
ZoomEventArgs.zoomTrigger - The type of zooming performed in the image editor.
Rotating event
The rotating
event is triggered when performing rotating the image. This event is passed an object that contains information about the rotating event, such as the amount of rotation performed. And this event uses RotateEventArgs
to handle the rotating action in the image.
The parameter available in the Rotating event is,
-
RotateEventArgs.previousDegree: The degree of rotation before the recent rotation action was applied in the Image Editor.
-
RotateEventArgs.currentDegree: The current degree of rotation after the rotation action has been performed in the Image Editor.
RotateEventArgs.cancel – Specifies a boolean value to cancel the rotating action.
Flipping event
The flipping
event is triggered when performing flipping the image. This event is passed an object that contains information about the flipping event, such as the amount of flip performed. And this event uses FlipEventArgs
to handle the flipping action in the image.
The parameter available in the flipping
event is,
-
FlipEventArgs.direction - The flip direction as ImageEditorDirection to be applied in the image editor.
-
FlipEventArgs.cancel - Specifies a boolean value to cancel the flip action.