1.1.0 • Published 4 years ago

react-image-markup v1.1.0

Weekly downloads
8
License
MIT
Repository
github
Last release
4 years ago

Markup Image with React.js (customizable)

npm.io npm.io

react-image-markup will provide you to edit uploaded image easily and save it.

Installation

npm i react-image-markup

or

yarn add react-image-markup

Usage

First import the Editor component inside your React component.

 import { Editor } from 'react-image-markup'

Then you'll be able to use Editor component.

Example:

You must give your editor component ref,which will help you to call the functions to set editor mode,clean objects or undo/redo your changes.

<Editor height="700" width="700" ref={this.editor} />

componentDidMount() {
    this.editor.current.set(this.editor.mode,this.editor.options)
}

width prop will set editor width

height prop will set editor height

ref with the help of ref, you will control the editor

Function set(type,params)

With the set() function you choose editor's mode,which should get two parameters type and params

Editor have 6 modes

  • text
  • circle
  • rect
  • selectMode
  • arrow
  • freeDrawing
  • crop

params parameter must be an object which set the type and every type have it's own options.

Text Mode

set('text',params) to enable text mode in editor,where params must be object and has it's default value
this.editor.current.set('text')
Object keyDefault ValueDescription
fillblackcolor
fontFamilyArialfont-family
fontSize32font-size
placeholderAdd Textdefault text placeholder when the text will be added

or you can customize your editor text mode styles by overwriting default values.

 let textModeOptions = { fill: 'red', fontFamily: 'Verdana',fontSize: 16, placeholder: 'Type something'}
 this.editor.current.set('text',textModeOptions)

Circle Mode

set('circle',params) to enable circle mode in editor,where params must be object and has it's default value
this.editor.current.set('circle')
Object keyDefault ValueDescription
filltransparentColor inside circle
strokeblackCirce border color
strokeWidth7Circle border width
disableCircleEditingfalseWhen false, can be painted custom circle. When true, always will be added circle of fixed height and width
top0Top position of an object
left0Left position of an object
radius20Radius of the circle
strokeUniformtrueWhen false, the stoke width will scale with the object. When true, the stroke will always match the exact pixel size entered for stroke width
noScaleCachefalseWhen true, cache does not get updated during scaling. The picture will get block if scaled too much and will be redrawn with correct details at the end of scaling. this setting is performance and application dependant

or you can customize your editor circle mode styles by overwriting default values.

 let circleModeParams = { fill: 'blue',stroke: 'white' }
 this.editor.current.set('circle',circleModeParams)

Rectangle Mode

set('rect',params) to enable rect mode in editor,where params must be object and has it's default value
this.editor.current.set('rect')
Object keyDefault ValueDescription
filltransparentColor inside rectangle
strokeblackRectangle is rendered via stroke and this property specifies its color
strokeWidth7Rectangle border width
angle0Angle of rotation of an object (in degrees)
width0if rectangle width and height is not 0,editor disable editing rectangle and add the rectangles with fixed properties
height0if rectangle width and height is not 0,editor disable editing rectangle and add the rectangles with fixed properties
top0Top position of rectangle
left0Left position of rectangle
opacity1Opacity of rectangle
strokeUniformtrueWhen false, the stoke width will scale with the object. When true, the stroke will always match the exact pixel size entered for stroke width
noScaleCachefalseWhen true, cache does not get updated during scaling. The picture will get block if scaled too much and will be redrawn with correct details at the end of scaling. this setting is performance and application dependant

or you can customize your editor rectangle mode styles by overwriting default values.

 let customizeRectangle = { fill: 'blue',stroke: 'white',strokeWidth: "5" }
 this.editor.current.set('rect',customizeRectangle)

Select Mode

set('selectMode') to enable select mode in editor. This mode disable all other types editing and enable select mode for user can move,resize or rotate selected object.This function hasn't params parameter
this.editor.current.set('selectMode')

Arrow Mode

set('arrow',params) to enable arrow mode in editor,where params must be object and has it's default value
this.editor.current.set('arrow')
Object keyDefault ValueDescription
strokeblackArrow is rendered via stroke and this property specifies its color
strokeWidth7Arrow border width
strokeUniformtrueWhen false, the stroke width will scale with the object. When true, the stroke will always match the exact pixel size entered for stroke width
noScaleCachefalseWhen true, cache does not get updated during scaling. The picture will get blocky if scaled too much and will be redrawn with correct details at the end of scaling. this setting is performance and application dependant

or you can customize your editor's arrow mode styles by overwriting default values.

 let customizeArrow = { stroke: 'red',strokeWidth: "3" }
 this.editor.current.set('arrow',customizeArrow)

Free Drawing Mode

set('freeDrawing',params) to enable free drawing mode in editor,where params must be object and has it's default value
this.editor.current.set('freeDrawing')
Object keyDefault ValueDescription
strokeblackbrush's color
strokeWidth7brush's width

or you can customize your editor's free drawing mode styles by overwriting default values.

 let customizeFreeDrawing = { stroke: 'yellow',strokeWidth: "5" }
 this.editor.current.set('freeDrawing',customizeFreeDrawing)

Crop Mode

set('crop') to enable crop mode in editor,where params must be cropper's parameters and has it's default value. After calling the function, the cropper will be shown in editor.
this.editor.current.set('crop',params)  
Object keyDefault ValueDescription
width200cropper's width
height200cropper's height
overlayColor#000color of background overlay
overlayOpacity0.7opacity of background overlay
transparentCornerfalsewhen set to true, cropper's controlling corners are rendered as transparent inside
hasRotatingPointfalsewhen set to false, cropper's controlling rotating point will not be visible or selectable
hasControlstruewhen set to false, cropper's controls are not displayed and can not be used to manipulate object
cornerSize10size of cropper's controlling corners (in pixels)
borderColor#000color of controlling borders of cropper (when it's active)
cornerColor#000color of controlling corners of the cropper (when it's active)
cornerStylecirclespecify style of control, 'rect' or 'circle'

or you can customize your editor crop mode styles by overwriting default values.

 let cropModeOptions = { width: '50', height: '100', overlayOpacity: '0.9'}
 this.editor.current.set('crop',cropModeOptions)

If you choose the area which will be cropped,you must call applyCropping() function.

 this.editor.current.applyCropping()

Function setBackgroundImage(imageUrl)

setBackgroundImage(imageUrl) to set editor background image
this.state = {
 imageUrl:"example.png"
}
componentDidMount{    
    this.editor.current.setBackgroundImage(this.state.imageUrl);
}

Function changeColor(colorHex)

changeColor(colorHex) to set color of tools
 this.editor.current.changeColor('#371492')

Function uploadImage(e)

uploadImage(e) to set background of canvas
 this.editor.current.uploadImage(e)

Function saveImage()

saveImage() to save your image,which returns image in base64 format.
 this.editor.current.saveImage()

Function saveImageAsFile()

saveImageAsFile() to save your image as file.
 this.editor.current.saveImageAsFile()

Function clear()

clear() function delete editor's all objects
 this.editor.current.clear()

Function undo()

With the help of undo() function you will be able to remove your last object you have added
 this.editor.current.undo()

Function redo()

With the help of redo() method you will be able to restore your last object which have been removed
 this.editor.current.redo()

Credits

1.1.0

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.1.0

5 years ago