Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getCroppedCanvas() method #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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