vue-image-markup will provide you to edit uploaded image easily and save it.
npm install vue-image-markupvue-image-markup will provide you to edit uploaded image easily and save it.
npm i vue-image-markup
or
yarn add vue-image-markup
First import the Editor component inside
your Vue component.
``vue`
import Editor from 'vue-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.`vue
mounted() {
$this.$refs.editor.set(this.editor.mode,this.editor.options);
}
`
canvasWidth prop will set editor width
canvasHeight prop will set editor height
ref with the help of ref, you will control the editor
editorId (optional) will set editor id, allowing the use of multiple editors in the same componenttypeFunction set(
,params)type
##### With the set() function you choose editor's mode,which should get two parameters and paramsparams
Editor have 7 modes
- text
- circle
- rect
- selectMode
- arrow
- freeDrawing
- crop
- eraser
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`javascript`
this.$refs.editor.set('text')black
Object key | Default Value | Description
------------- | ------------- | -------------
fill | | colorArial
fontFamily | | font-family32
fontSize | | font-size100
fontWeight | | font-weight(100,200,300,400,500,600,700,bold,normal)normal
fontStyle | | font-style(normal,italic,oblique)Add Text
placeholder | | default text placeholder when the text will be added''
id | | text id`
or you can customize your editor text mode styles by overwriting default values.javascript`
let textModeOptions = { id: 'title', fill: 'red', fontFamily: 'Verdana',fontSize: 16, placeholder: 'Type something'}
this.$refs.editor.set('text',textModeOptions)set('circle',params)
#### Circle Mode
##### to enable circle mode in editor,where params must be object and has it's default value`javascript`
this.$refs.editor.set('circle')transparent
Object key | Default Value | Description
------------- | ------------- | -------------
fill | | Color inside circleblack
stroke | | Circe border color7
strokeWidth | | Circle border widthfalse
disableCircleEditing| | When false, can be painted custom circle. When true, always will be added circle of fixed height and width0
top | | Top position of an object 0
left | |Left position of an object 20
radius | | Radius of the circletrue
strokeUniform | | When false, the stoke width will scale with the object. When true, the stroke will always match the exact pixel size entered for stroke widthfalse
noScaleCache | |When 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''
id | | Circle id
or you can customize your editor circle mode styles by overwriting default values.
`javascript`
let circleModeParams = { fill: 'blue',stroke: 'white' }
this.$refs.editor.set('circle',circleModeParams)set('rect',params)
#### Rectangle Mode
##### to enable rect mode in editor,where params must be object and has it's default value`javascript`
this.$refs.editor.set('rect')transparent
Object key | Default Value | Description
------------- | ------------- | -------------
fill | | Color inside rectangleblack
stroke | | Rectangle is rendered via stroke and this property specifies its color7
strokeWidth | | Rectangle border width0
angle | | Angle of rotation of an object (in degrees)0
width | | if rectangle width and height is not 0,editor disable editing rectangle and add the rectangles with fixed properties 0
height | | if rectangle width and height is not 0,editor disable editing rectangle and add the rectangles with fixed properties 0
top | | Top position of rectangle 0
left | |Left position of rectangle 1
opacity | | Opacity of rectangletrue
strokeUniform | | When false, the stoke width will scale with the object. When true, the stroke will always match the exact pixel size entered for stroke widthfalse
noScaleCache | |When 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''
id | | Rectangle id`
or you can customize your editor rectangle mode styles by overwriting default values. javascript`
let customizeRectangle = { fill: 'blue',stroke: 'white',strokeWidth: "5" }
this.$refs.editor.set('rect',customizeRectangle)set('selectMode')
#### Select Mode
##### 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
`javascript`
this.$refs.editor.set('selectMode')set('arrow',params)
#### Arrow Mode
##### to enable arrow mode in editor,where params must be object and has it's default value`javascript`
this.$refs.editor.set('arrow')black
Object key | Default Value | Description
------------- | ------------- | -------------
stroke | | Arrow is rendered via stroke and this property specifies its color7
strokeWidth | | Arrow border widthtrue
strokeUniform | | When false, the stroke width will scale with the object. When true, the stroke will always match the exact pixel size entered for stroke widthfalse
noScaleCache | |When 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''
id | | Arrow id`
or you can customize your editor's arrow mode styles by overwriting default values. javascript`
let customizeArrow = { stroke: 'red',strokeWidth: "3" }
this.$refs.editor.set('arrow',customizeArrow)set('freeDrawing',params)
#### Free Drawing Mode
##### to enable free drawing mode in editor,where params must be object and has it's default value`javascript`
this.$refs.editor.set('freeDrawing')black
Object key | Default Value | Description
------------- | ------------- | -------------
stroke | | brush's color7
strokeWidth | | brush's width
or you can customize your editor's free drawing mode styles by overwriting default values.
`javascript`
let customizeFreeDrawing = { stroke: 'yellow',strokeWidth: "5" }
this.$refs.editor.set('freeDrawing',customizeFreeDrawing)set('crop')
#### Crop Mode
##### 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.`javascript`
this.$refs.editor.set('crop',params) 200
Object key | Default Value | Description
------------- | ------------- | -------------
width | | cropper's width200
height | | cropper's height#000
overlayColor | | color of background overlay0.7
overlayOpacity | | opacity of background overlayfalse
transparentCorner | | when set to true, cropper's controlling corners are rendered as transparent insidefalse
hasRotatingPoint | | when set to false, cropper's controlling rotating point will not be visible or selectabletrue
hasControls | | when set to false, cropper's controls are not displayed and can not be used to manipulate object10
cornerSize | | size of cropper's controlling corners (in pixels)#000
borderColor | | color of controlling borders of cropper (when it's active)#000
cornerColor | | color of controlling corners of the cropper (when it's active)circle
cornerStyle | | specify style of control, 'rect' or 'circle'
or you can customize your editor crop mode styles by overwriting default values.
`javascript`
let cropModeOptions = { width: '50', height: '100', overlayOpacity: '0.9'}
this.$refs.editor.set('crop',cropModeOptions)
If you choose the area which will be cropped,you must call applyCropping() function.`javascript`
this.$refs.editor.applyCropping()set('eraser')
#### Eraser Mode
##### to enable eraser mode in editor, which will remove the object from editor when the object will be clicked.`javascript`
this.$refs.editor.set('eraser')
to set editor background image
`vue
data(){
return{
imageUrl:"example.png"
}
},
mounted:{
this.$refs.editor.setBackgroundImage(this.imageUrl);
}
`Function uploadImage(e)
##### uploadImage(e) to set background of canvas
`javascript
this.$refs.editor.uploadImage(e)
`
Function saveImage()
##### saveImage() to save your image,which returns image in base64 format.
`javascript
this.$refs.editor.saveImage()
`Function clear()
##### clear() function delete editor's all objects
`javascript
this.$refs.editor.clear()
`
Function undo()
##### With the help of undo() function you will be able to remove your last object you have added
`javascript
this.$refs.editor.undo()
`
Function redo()
##### With the help of redo() method you will be able to restore your last object which have been removed
`javascript
this.$refs.editor.redo()
`Function getObjectsById(id)
##### With the help of getObjectsById(id) method you will be able to get object by id
`javascript
this.$refs.editor.getObjectsById('title')
``