Frame in React Image Editor
03 Sep 202612 minutes to read
The frame feature in an React Image Editor provides users with the capability to add decorative borders or frames around their images. Frames are a visual design element that can enhance the overall appearance and appeal of an image.
Apply frame to the image
The drawFrame method is a function designed to enable the application of various frame options to an image. This method simplifies the process of adding decorative frames, such as mat, bevel, line, hook, and inset, to an image by allowing users to specify their desired frame type.
Depending on the frame type selected, users may have additional customization options, such as adjusting the frame’s thickness, color, texture, or other attributes. This allows for fine-tuning the appearance of the frame to match the image’s theme or the user’s preferences.
The drawFrame method in the React Image Editor control takes nine parameters to define the frame properties:
-
frameType- Specifies the frame type (for example:mat,bevel,line,hook,inset). -
color- Specifies the color for the frame. -
gradientColor- Specifies the gradient color for the frame. -
size- Specifies the size (thickness) of the frame. -
inset- Specifies the inset value for applicable frame types. -
offset- Specifies the offset value for line and inset type frames. -
borderRadius- Specifies the border radius for line-type frames. -
frameLineStyle- Specifies the frame line style for line-type frames (for example:solid,dashed,dotted). -
lineCount- Specifies the number of lines for the line-type frame.
In the following example, you can use the drawFrame method in the button click event.
import { ImageEditorComponent, FrameType, FrameLineStyle } from '@syncfusion/ej2-react-image-editor';
import { ButtonComponent } from '@syncfusion/ej2-react-buttons';
import { Browser } from '@syncfusion/ej2-base';
import * as React from 'react';
import * as ReactDOM from "react-dom";
export default class App extends React.Component {
imgObj;
imageEditorCreated() {
if (Browser.isDevice) {
this.imgObj.open('https://ej2.syncfusion.com/react/documentation/image-editor/images/flower.jpeg');
}
else {
this.imgObj.open('https://ej2.syncfusion.com/react/documentation/image-editor/images/bridge.jpeg');
}
}
matClick() {
this.imgObj.drawFrame(FrameType.Line, 'red', 'blue', 20, 20, 20, 20, FrameLineStyle.Solid, 1);
}
bevelClick() {
this.imgObj.drawFrame(FrameType.Bevel, 'red', 'blue', 20, 20, 20, 20, FrameLineStyle.Solid, 1);
}
lineClick() {
this.imgObj.drawFrame(FrameType.Line, 'red', 'blue', 20, 20, 20, 20, FrameLineStyle.Solid, 1);
}
insetClick() {
this.imgObj.drawFrame(FrameType.Inset, 'red', 'blue', 20, 20, 20, 20, FrameLineStyle.Solid, 1);
}
hookClick() {
this.imgObj.drawFrame(FrameType.Hook, 'red', 'blue', 20, 20, 20, 20, FrameLineStyle.Solid, 1);
}
render() {
return (<div className='e-img-editor-sample'>
<ImageEditorComponent ref={(img) => { this.imgObj = img; }} height="350px" created={this.imageEditorCreated.bind(this)} toolbar = {[]}>
</ImageEditorComponent>
<div>
<ButtonComponent cssClass='e-primary' content='Mat' onClick={this.matClick.bind(this)}/>
<ButtonComponent cssClass='e-primary' content='Bevel' onClick={this.bevelClick.bind(this)}/>
<ButtonComponent cssClass='e-primary' content='Line' onClick={this.lineClick.bind(this)}/>
<ButtonComponent cssClass='e-primary' content='Inset' onClick={this.insetClick.bind(this)}/>
<ButtonComponent cssClass='e-primary' content='Hook' onClick={this.hookClick.bind(this)}/>
</div>
</div>);
}
}
ReactDOM.render(<App />, document.getElementById('image-editor'));import { ImageEditorComponent, FrameType, FrameLineStyle } from '@syncfusion/ej2-react-image-editor';
import { ButtonComponent } from '@syncfusion/ej2-react-buttons';
import { Browser } from '@syncfusion/ej2-base';
import * as React from 'react';
import * as ReactDOM from "react-dom";
function App() {
let imgObj: ImageEditorComponent;
function imageEditorCreated(): void {
if (Browser.isDevice) {
imgObj.open('https://ej2.syncfusion.com/react/documentation/image-editor/images/flower.jpeg');
} else {
imgObj.open('https://ej2.syncfusion.com/react/documentation/image-editor/images/bridge.jpeg');
}
}
function matClick(): void {
imgObj.drawFrame(FrameType.Mat, 'red', 'blue', 20, 20, 20, 20, FrameLineStyle.Solid, 1);
}
function bevelClick(): void {
imgObj.drawFrame(FrameType.Bevel, 'red', 'blue', 20, 20, 20, 20, FrameLineStyle.Solid, 1);
}
function lineClick(): void {
imgObj.drawFrame(FrameType.Line, 'red', 'blue', 20, 20, 20, 20, FrameLineStyle.Solid, 1);
}
function insetClick(): void {
imgObj.drawFrame(FrameType.Inset, 'red', 'blue', 20, 20, 20, 20, FrameLineStyle.Solid, 1);
}
function hookClick(): void {
imgObj.drawFrame(FrameType.Hook, 'red', 'blue', 20, 20, 20, 20, FrameLineStyle.Solid, 1);
}
return (
<div className='e-img-editor-sample'>
<ImageEditorComponent ref={(img) => { imgObj = img }} created={imageEditorCreated} toolbar = {[]}>
</ImageEditorComponent>
<div>
<ButtonComponent cssClass='e-primary' content='Mat' onClick = {matClick}/>
<ButtonComponent cssClass='e-primary' content='Bevel' onClick = {bevelClick}/>
<ButtonComponent cssClass='e-primary' content='Line' onClick = {lineClick}/>
<ButtonComponent cssClass='e-primary' content='Inset' onClick = {insetClick}/>
<ButtonComponent cssClass='e-primary' content='Hook' onClick = {hookClick}/>
</div>
</div>
);
}
export default App;
ReactDOM.render(<App />, document.getElementById('image-editor'));<!DOCTYPE html>
<html lang="en">
<head>
<title>Syncfusion React Image Editor</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Essential JS 2 for React Components" />
<meta name="author" content="Syncfusion" />
<link href="https://cdn.syncfusion.com/ej2/35.2.12/tailwind3.css"rel="stylesheet">
<link href="index.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
</head>
<body>
<div id='image-editor'>
<div id='loader'>Loading....</div>
</div>
</body>
</html>Frame changing event
The frameChanging event is triggered when applying a frame to the image. This event provides information encapsulated within an object that includes details about the frame change, such as the frame type and customization values.
The parameters available in FrameChangeEventArgs are:
-
FrameChangeEventArgs.previousFrameSetting- The frame settings (size, color, inset, offset, gradientColor) that were applied before the change. -
FrameChangeEventArgs.currentFrameSetting- The frame settings that will be applied after the change. -
FrameChangeEventArgs.cancel- A boolean value to cancel the frame-changing action.