Skip to content

Commit

Permalink
Add getCroppedCanvas() method
Browse files Browse the repository at this point in the history
  • Loading branch information
Kacper Banasik committed Aug 29, 2018
1 parent 90d07aa commit 8b6d4df
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 33 deletions.
13 changes: 10 additions & 3 deletions component/Cropper.js
Original file line number Diff line number Diff line change
Expand Up @@ -496,10 +496,10 @@ class Cropper extends Component {
}
}

// crop image
crop () {
// get cropped canvas
getCroppedCanvas () {
const img = findDOMNode(this.img)
let canvas = document.createElement('canvas')
const canvas = document.createElement('canvas')
const {
x,
y,
Expand All @@ -510,6 +510,13 @@ class Cropper extends Component {
canvas.width = width
canvas.height = height
canvas.getContext('2d').drawImage(img, x, y, width, height, 0, 0, width, height)
return canvas
}

// crop image
crop () {
const canvas = this.getCroppedCanvas()

return canvas.toDataURL()
}

Expand Down
61 changes: 34 additions & 27 deletions dist/app.js

Large diffs are not rendered by default.

16 changes: 13 additions & 3 deletions lib/Cropper.js
Original file line number Diff line number Diff line change
Expand Up @@ -540,11 +540,11 @@ var Cropper = function (_Component) {
}
}

// crop image
// get cropped canvas

}, {
key: 'crop',
value: function crop() {
key: 'getCroppedCanvas',
value: function getCroppedCanvas() {
var img = findDOMNode(this.img);
var canvas = document.createElement('canvas');
var _values$original = this.values().original,
Expand All @@ -557,6 +557,16 @@ var Cropper = function (_Component) {
canvas.width = width;
canvas.height = height;
canvas.getContext('2d').drawImage(img, x, y, width, height, 0, 0, width, height);
return canvas;
}

// crop image

}, {
key: 'crop',
value: function crop() {
var canvas = this.getCroppedCanvas();

return canvas.toDataURL();
}

Expand Down

0 comments on commit 8b6d4df

Please sign in to comment.