Skip to content

Commit

Permalink
add cropper's grid
Browse files Browse the repository at this point in the history
  • Loading branch information
lilitsimonyan98 committed Feb 4, 2020
1 parent b7b349c commit 4db8e8c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea
node_modules
node_modules
.history
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ Object key | Default Value | Description
width | `200` | cropper's width
height | `200` | cropper's height
overlayColor | `#000` | color of background overlay
overlayOpacity | `0.3` | opacity of background overlay
overlayOpacity | `0.7` | opacity of background overlay
transparentCorner | `false` | when set to `true`, cropper's controlling corners are rendered as transparent inside
hasRotatingPoint | `false` | when set to `false`, cropper's controlling rotating point will not be visible or selectable
hasControls | `true` | when set to `false`, cropper's controls are not displayed and can not be used to manipulate object
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-image-markup",
"version": "2.0.1",
"version": "2.0.2",
"description": "vue-image-markup will provide you to edit uploaded image easily and save it.",
"main": "src/Editor.vue",
"repository": {
Expand Down
3 changes: 2 additions & 1 deletion src/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
},
clear() {
this.canvas.clear();
this.cancelCroppingImage()
},
changeColor(colorProperty) {
this.color = colorProperty;
Expand Down Expand Up @@ -184,7 +185,7 @@
width: (params && params.width) ? params.width : 200,
height: (params && params.height) ? params.height : 200,
overlayColor: (params && params.overlayColor) ? params.overlayColor : "#000",
overlayOpacity: (params && params.overlayOpacity) ? params.overlayOpacity : 0.3,
overlayOpacity: (params && params.overlayOpacity) ? params.overlayOpacity : 0.7,
transparentCorner: (params && params.transparentCorner) ? params.transparentCorner : false,
hasRotatingPoint: (params && params.hasRotatingPoint) ? params.hasRotatingPoint : false,
hasControls: (params && params.hasControls) ? params.hasControls : true,
Expand Down
33 changes: 25 additions & 8 deletions src/assets/js/crop.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default (function () {
left: (oImg1.width - properties.width)/ 2,
top: (oImg1.height - properties.height)/ 2,
width: properties.width,
height: properties.height,
height: properties.height,
fill: '',
imageWidth: oImg1.width,
imageHeight: oImg1.height,
Expand All @@ -82,7 +82,24 @@ export default (function () {
cornerStyle: properties.cornerStyle,
transparentCorners: properties.transparentCorners,
hasRotatingPoint: properties.hasRotatingPoint,

lockUniScaling:true,
noScaleCache:false,
strokeUniform:true,
clipTo: function(context) {
context.translate(- this.width/2, - this.height/2);

for (let x = 0; x <= this.width; x += this.width/3) {
context.moveTo(x , 0);
context.lineTo(x, this.height);
}

for (let y = 0; y <= this.height; y += this.height/3) {
context.moveTo(0, y);
context.lineTo(this.width, y);
}
context.strokeStyle = "rgba(0,0,0,0.4)";
context.stroke();
}
});
clipRect = new fabric.Rect({
left: -(properties.width /2),
Expand Down Expand Up @@ -113,12 +130,12 @@ export default (function () {
clipRect = new fabric.Rect({
left: target.left - (overlay.width / 2),
top: target.top - (overlay.height / 2),
width: properties.width,
height: properties.height,
width: target.width,
height: target.height,
fill: '',
scaleX: target.scaleX,
scaleY: target.scaleY,
});
scaleY: target.scaleY,
});
overlay.set("clipPath",clipRect)
inst.canvas.renderAll()

Expand All @@ -128,8 +145,8 @@ export default (function () {
clipRect = new fabric.Rect({
left: target.left - (overlay.width / 2),
top: target.top - (overlay.height / 2),
width: properties.width,
height: properties.height,
width: target.width,
height: target.height,
fill: '',
scaleX: target.scaleX,
scaleY: target.scaleY,
Expand Down

0 comments on commit 4db8e8c

Please sign in to comment.