Filters in the Angular Image Editor component

26 Mar 20255 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 toolbar, the default filter can be applied by clicking the Filter option in the toolbar and picking the Default filter.

In the following example, you can using the applyImageFilter method in the button click event.

import { NgModule } from '@angular/core'
import { BrowserModule} from '@angular/platform-browser'
import { ImageEditorModule } from '@syncfusion/ej2-angular-image-editor'
import { enableRipple } from '@syncfusion/ej2-base'



import { Component,ViewChild } from '@angular/core';
import { Browser } from '@syncfusion/ej2-base';
import { ImageEditorComponent, ImageFilterOption } from '@syncfusion/ej2-angular-image-editor';

@Component({
imports: [
        
        ImageEditorModule
    ],


standalone: true,
    selector: 'app-root',
    template: `<div class="e-section-control">
              <!-- To render Image Editor. -->
              <div id="wrapperDiv" style="width:550px;height:350px;">
                <ejs-imageeditor #imageEditor (created)="created()"></ejs-imageeditor>
              </div>
              <button class="e-btn e-primary" (click)="chromeClick()">Chrome</button>
              <button class="e-btn e-primary" (click)="coldClick()">Cold</button>
              <button class="e-btn e-primary" (click)="warmClick()">Warm</button>
              <button class="e-btn e-primary" (click)="grayScaleClick()">GrayScale</button>
              <button class="e-btn e-primary" (click)="sepiaClick()">Sepia</button>
              <button class="e-btn e-primary" (click)="invertClick()">Invert</button>
              </div>`
})

export class AppComponent {
    @ViewChild('imageEditor')
    public imageEditorObj?: ImageEditorComponent;

      public created(): void {
      if (Browser.isDevice) {
        this.imageEditorObj?.open('./flower.png');        
      } 
      else {
        this.imageEditorObj?.open('./bridge.png');
      }
    }
    chromeClick(): void {
        this.imageEditorObj?.applyImageFilter(ImageFilterOption.Chrome);
    }
    coldClick(): void {
        this.imageEditorObj?.applyImageFilter(ImageFilterOption.Cold);
    }
    warmClick(): void {
        this.imageEditorObj?.applyImageFilter(ImageFilterOption.Warm);
    }
    grayScaleClick(): void {
        this.imageEditorObj?.applyImageFilter(ImageFilterOption.Grayscale);
    }
    sepiaClick(): void {
        this.imageEditorObj?.applyImageFilter(ImageFilterOption.Sepia);
    }
    invertClick(): void {
        this.imageEditorObj?.applyImageFilter(ImageFilterOption.Invert);
    }
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));

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.