Skip to content

Commit

Permalink
Change cropper's size according to image size
Browse files Browse the repository at this point in the history
  • Loading branch information
lilitsimonyan98 committed Apr 21, 2020
1 parent 212bef2 commit e5f1997
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
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": "3.0.9",
"version": "3.0.10",
"description": "vue-image-markup will provide you to edit uploaded image easily and save it.",
"main": "src/Editor.vue",
"repository": {
Expand Down
24 changes: 16 additions & 8 deletions src/assets/js/crop.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export default (function () {
let drag;
let clipRect, rect, rectRed;
let overlay = {};
let properties
let properties;
let cropperWidth,cropperHeight;

function CropImage(canvas, draggable = false, apply = false, cancel = false, params) {
this.canvas = canvas;
Expand Down Expand Up @@ -62,7 +63,14 @@ export default (function () {
new CanvasHistory(this.canvas, croppedImage);
return CropImage
}

if(canvas.width <= properties.width || canvas.height <= properties.height){
cropperWidth = canvas.width - 50;
cropperHeight = canvas.height - 50;
}
else{
cropperWidth = properties.width;
cropperHeight = properties.height;
}
this.bindEvents();
this.canvas.selectable = false;
this.canvas.renderAll();
Expand All @@ -82,8 +90,8 @@ export default (function () {
rectRed = new fabric.Rect({
left: (oImg1.width - properties.width) / 2,
top: (oImg1.height - properties.height) / 2,
width: properties.width,
height: properties.height,
width: cropperWidth,
height: cropperHeight,
fill: '',
imageWidth: oImg1.width,
imageHeight: oImg1.height,
Expand Down Expand Up @@ -113,10 +121,10 @@ export default (function () {
}
});
clipRect = new fabric.Rect({
left: -(properties.width / 2),
top: -(properties.height / 2),
width: properties.width,
height: properties.height,
left: -(cropperWidth / 2),
top: -(cropperHeight / 2),
width: cropperWidth,
height: cropperHeight,
fill: '',
selectable: false,
});
Expand Down

0 comments on commit e5f1997

Please sign in to comment.