- Apply filter effect
- Image filtering event
Contact Support
Filters in the EJ2 TypeScript Image Editor control
25 Mar 20256 minutes to read
Filters are pre-defined effects that can be applied to an image to alter its appearance or mood. Image filters can be used to add visual interest or to enhance certain features of the image. Some common types of image filters include cold, warm, chrome, sepia, and invert. This can be done by either using the toolbar or the applyImageFilter
method which takes a single parameter: the filter applied to an image.
Apply filter effect
The applyImageFilter
method is utilized to apply filters to an image. By passing the desired filter type as the first parameter of the method, specified as ImageFilterOption
the method applies the corresponding filter to the image. This allows for easy and convenient application of various filters to enhance or modify the image based on the chosen filter type.
- filterOption - Specifies the filter options to the image.
In the following example, you can using the applyImageFilter
method in the button click event.
import { ImageEditor, ImageFilterOption } from '@syncfusion/ej2-image-editor';
import { Button } from '@syncfusion/ej2-buttons';
import { Browser } from '@syncfusion/ej2-base';
//Image Editor items definition
let imageEditorObj: ImageEditor = new ImageEditor({
width: '550px',
height: '330px',
toolbar: [],
created: () => {
if (Browser.isDevice) {
imageEditorObj.open('bee-eater.png');
} else {
imageEditorObj.open('bee-eater.png');
}
}
});
imageEditorObj.appendTo('#imageeditor');
//Button click
document.getElementById('chromeClick').onclick = (): void => {
imageEditorObj.applyImageFilter(ImageFilterOption.Chrome);
}
document.getElementById('coldClick').onclick = (): void => {
imageEditorObj.applyImageFilter(ImageFilterOption.Cold);
}
document.getElementById('warmClick').onclick = (): void => {
imageEditorObj.applyImageFilter(ImageFilterOption.Warm);
}
document.getElementById('grayscaleClick').onclick = (): void => {
imageEditorObj.applyImageFilter(ImageFilterOption.Grayscale);
}
document.getElementById('sepiaClick').onclick = (): void => {
imageEditorObj.applyImageFilter(ImageFilterOption.Sepia);
}
document.getElementById('invertClick').onclick = (): void => {
imageEditorObj.applyImageFilter(ImageFilterOption.Invert);
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Essential JS 2</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" />
<meta name="description" content="Essential JS 2" />
<meta name="author" content="Syncfusion" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-buttons/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-inputs/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-lists/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-navigations/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-popups/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-splitbuttons/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-image-editor/styles/material.css" rel="stylesheet" />
<!--style reference from app-->
<link href="styles.css" rel="stylesheet" />
<!--system js reference and configuration-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>LOADING....</div>
<div id='container'>
<div class="control-section">
<div id="imageeditor" class="row">
</div>
<div>
<button id='chromeClick' class='e-btn e-primary' >Chrome</button>
<button id='coldClick' class='e-btn e-primary' >Cold</button>
<button id='warmClick' class='e-btn e-primary' >Warm</button>
<button id='grayscaleClick' class='e-btn e-primary' >Grayscale</button>
<button id='sepiaClick' class='e-btn e-primary' >Sepia</button>
<button id='invertClick' class='e-btn e-primary' >Invert</button>
</div>
</div>
</div>
</body>
</html>
Image filtering event
The imageFiltering
event is triggered when applying filtering on the image. This event is passed an object that contains information about the filtering event, such as the type of filtering.
The parameter available in the ImageFilterEventArgs
event is,
ImageFilterEventArgs.filter - The type of filtering as ImageFilterOption
to be applied in the image editor.
ImageFilterEventArgs.cancel – Specifies to cancel the filtering action.