Annotation in Angular Image editor component
23 Dec 202218 minutes to read
The Image Editor has multiple annotations support including text, freehand drawings, and shapes such as rectangles, ellipses, and lines.
Text
The Text annotation can be inserted and customized by changing its color, font family, font size, and font styles such as bold and italic. The text annotation can be made by either using a toolbar or drawText
method.
In drawText
method, the text annotation can be inserted by specifying the text, font family, font size, and font styles. The drawText
method has the following parameters.
-
x - Specifies x-coordinate of the text
-
y - Specifies y-coordinate of the text
-
text - Specifies the text to add to an image
-
fontFamily - Specifies the font family of the text.
-
fontSize - Specifies the font size of the text.
-
bold - Specifies whether the text is bold or not.
-
italic - Specifies whether the text is italic or not.
-
color - Specifies font color of the text.
In the toolbar, the text annotation can be inserted by clicking the Annotation dropdown button and picking the Add Text option from that popup. Once the text is inserted, the contextual toolbar will be enabled for customizing its color, font family, font size, and font styles such as bold and italic.
In the following example, you can using the drawText method in the button click event.
import { Component,ViewChild } from '@angular/core';
import { Browser } from '@syncfusion/ej2-base';
import { ImageEditorComponent } from '@syncfusion/ej2-angular-image-editor';
@Component({
selector: 'app-root',
template: `<!-- 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)="btnClick()">Click</button>`
})
export class AppComponent {
@ViewChild('imageEditor')
public imageEditorObj: ImageEditorComponent;
public created(): void {
if (Browser.isDevice) {
this.imageEditorObj.open('https://ej2.syncfusion.com/demos/src/image-editor/images/flower.png');
} else {
this.imageEditorObj.open('https://ej2.syncfusion.com/demos/src/image-editor/images/bridge.png');
}
}
btnClick(): void {
this.imageEditorObj.drawText(500, 500, 'Syncfusion', 'Arial', 100, true, true, '#000');
}
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ImageEditorModule } from '@syncfusion/ej2-angular-image-editor';
import { AppComponent } from './app.component';
import { enableRipple } from '@syncfusion/ej2-base';
enableRipple(true);
/**
* Module
*/
@NgModule({
imports: [
BrowserModule,
ImageEditorModule
],
declarations: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';
enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);
Freehand Draw
This annotation can be customized by changing the pen color and stroke width and it can be made by either using a toolbar or the freeHandDraw
method.
The freeHandDraw
method is used to enable or disable a freehand drawing option in an Image Editor.
In the toolbar, the freehand draw annotation can be inserted by clicking the Annotation dropdown button and picking the Pen option from that popup. Once the freehand draw is enabled, the contextual toolbar will be enabled.
In the following example, the freeHandDraw
method is used to toggle the freehand drawings.
import { Component,ViewChild } from '@angular/core';
import { Browser } from '@syncfusion/ej2-base';
import { ImageEditorComponent } from '@syncfusion/ej2-angular-image-editor';
@Component({
selector: 'app-root',
template: `<!-- 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)="btnClick()">Click</button>
<button class="e-btn e-primary" (click)="applyBtnClick()">Apply</button>`
})
export class AppComponent {
@ViewChild('imageEditor')
public imageEditorObj: ImageEditorComponent;
public created(): void {
if (Browser.isDevice) {
this.imageEditorObj.open('https://ej2.syncfusion.com/demos/src/image-editor/images/flower.png');
} else {
this.imageEditorObj.open('https://ej2.syncfusion.com/demos/src/image-editor/images/bridge.png');
}
}
btnClick(): void {
this.imageEditorObj.freeHandDraw(true);
}
applyBtnClick(): void {
this.imageEditorObj.freeHandDraw(false);
}
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ImageEditorModule } from '@syncfusion/ej2-angular-image-editor';
import { AppComponent } from './app.component';
import { enableRipple } from '@syncfusion/ej2-base';
enableRipple(true);
/**
* Module
*/
@NgModule({
imports: [
BrowserModule,
ImageEditorModule
],
declarations: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';
enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);
Shapes
The shape annotations include rectangles, ellipses, and lines. The border color, fill color, and border width of the shapes can be customized.
Rectangle
The Rectangle shape can be inserted and customized by changing its border color, fill color, and border width. The Rectangle shape can be made by either using a toolbar or the drawRectangle
method.
In the drawRectangle
method, the rectangle shape can be inserted by specifying fillcolor, stroke color and stroke width. The drawRectangle
method has the following parameters.
* x - Specifies the x-coordinate of the rectangle.
* y - Specifies the y-coordinate of the rectangle.
* width - Specifies the width of the rectangle.
* height - Specifies the height of the rectangle.
* strokeWidth - Specifies the stroke width of the rectangle.
* strokeColor - Specifies the stroke color of the rectangle.
* fillColor - the fill color of the rectangle.
In the toolbar, the Rectangle shape can be inserted by clicking the Annotation dropdown button and picking the Rectangle option from that popup. Once the shape is inserted, the contextual toolbar will be enabled for customizing its fill color, stroke color, and stroke width.
In the following example, the drawRectangle
method is used to draw the rectangle.
import { Component,ViewChild } from '@angular/core';
import { Browser } from '@syncfusion/ej2-base';
import { ImageEditorComponent } from '@syncfusion/ej2-angular-image-editor';
@Component({
selector: 'app-root',
template: `<!-- 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)="btnClick()">Click</button>`
})
export class AppComponent {
@ViewChild('imageEditor')
public imageEditorObj: ImageEditorComponent;
public created(): void {
if (Browser.isDevice) {
this.imageEditorObj.open('https://ej2.syncfusion.com/demos/src/image-editor/images/flower.png');
} else {
this.imageEditorObj.open('https://ej2.syncfusion.com/demos/src/image-editor/images/bridge.png');
}
}
btnClick(): void {
this.imageEditorObj.drawRectangle(500, 500, 400, 400, 2, "#fff", 'blue');
}
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ImageEditorModule } from '@syncfusion/ej2-angular-image-editor';
import { AppComponent } from './app.component';
import { enableRipple } from '@syncfusion/ej2-base';
enableRipple(true);
/**
* Module
*/
@NgModule({
imports: [
BrowserModule,
ImageEditorModule
],
declarations: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';
enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);
Ellipse
The Ellipse shape can be inserted and customized by changing its border color, fill color, and border width. The Ellipse shape can be made by either using a toolbar or the drawEllipse
method.
In the drawEllipse
method, the ellipse shape can be inserted by specifying fillcolor, stroke color and stroke width. The drawEllipse
method has the following parameters.
* x - Specifies the x-coordinate of the ellipse.
* y - Specifies the y-coordinate of the ellipse.
* radiusX - the radius x point for the ellipse.
* radiusY - the radius y point for the ellipse.
* strokeWidth - the stroke width of the ellipse.
* strokeColor - the stroke color of the ellipse.
* fillColor - the fill color of the ellipse.
In the toolbar, the Ellipse shape can be inserted by clicking the Annotation dropdown button and picking the Ellipse option from that popup. Once the shape is inserted, the contextual toolbar will be enabled for customizing its fill color, stroke color, and stroke width.
In the following example, the drawEllipse
method is used to draw the ellipse.
import { Component,ViewChild } from '@angular/core';
import { Browser } from '@syncfusion/ej2-base';
import { ImageEditorComponent } from '@syncfusion/ej2-angular-image-editor';
@Component({
selector: 'app-root',
template: `<!-- 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)="btnClick()">Click</button>`
})
export class AppComponent {
@ViewChild('imageEditor')
public imageEditorObj: ImageEditorComponent;
public created(): void {
if (Browser.isDevice) {
this.imageEditorObj.open('https://ej2.syncfusion.com/demos/src/image-editor/images/flower.png');
} else {
this.imageEditorObj.open('https://ej2.syncfusion.com/demos/src/image-editor/images/bridge.png');
}
}
btnClick(): void {
this.imageEditorObj.drawEllipse(500, 500, 400, 400, 2, "#fff", 'green');
}
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ImageEditorModule } from '@syncfusion/ej2-angular-image-editor';
import { AppComponent } from './app.component';
import { enableRipple } from '@syncfusion/ej2-base';
enableRipple(true);
/**
* Module
*/
@NgModule({
imports: [
BrowserModule,
ImageEditorModule
],
declarations: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';
enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);
Line
The line shape can be inserted and customized by changing its border color, and border width. The Line shape can be made by either using a toolbar or the drawLine
method.
In the drawLine
method, the line shape can be inserted by specifying, stroke color and stroke width. The drawLine
method has the following parameters:
* startX – Specifies start point x-coordinate of line.
* startY – Specifies start point y-coordinate of line.
* endX - Specifies endpoint x-coordinates of line.
* endY - Specifies end point y-coordinates of the line.
* strokeWidth - Specifies the stroke width of the line.
* strokeColor - Specifies the stroke color of the line.
In the toolbar, the Line shape can be inserted by clicking the Annotation dropdown button and picking the Line option from that popup. Once the line shape is inserted, the contextual toolbar will be enabled for customizing its stroke color, and stroke width.
In the following example, the drawLine
method is used to draw the line.
import { Component,ViewChild } from '@angular/core';
import { Browser } from '@syncfusion/ej2-base';
import { ImageEditorComponent } from '@syncfusion/ej2-angular-image-editor';
@Component({
selector: 'app-root',
template: `<!-- 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)="btnClick()">Click</button>`
})
export class AppComponent {
@ViewChild('imageEditor')
public imageEditorObj: ImageEditorComponent;
public created(): void {
if (Browser.isDevice) {
this.imageEditorObj.open('https://ej2.syncfusion.com/demos/src/image-editor/images/flower.png');
} else {
this.imageEditorObj.open('https://ej2.syncfusion.com/demos/src/image-editor/images/bridge.png');
}
}
btnClick(): void {
this.imageEditorObj.drawLine(600, 600, 40, 40, 8, "blue");
}
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ImageEditorModule } from '@syncfusion/ej2-angular-image-editor';
import { AppComponent } from './app.component';
import { enableRipple } from '@syncfusion/ej2-base';
enableRipple(true);
/**
* Module
*/
@NgModule({
imports: [
BrowserModule,
ImageEditorModule
],
declarations: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';
enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);