Skip to content

Commit d70f3fd

Browse files
author
Kacper Banasik
committed
Add getCroppedCanvas() method
Signed-off-by: Kacper Banasik <kbanasik@bluesoft.net.pl>
1 parent 90d07aa commit d70f3fd

File tree

3 files changed

+57
-33
lines changed

3 files changed

+57
-33
lines changed

component/Cropper.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -496,10 +496,10 @@ class Cropper extends Component {
496496
}
497497
}
498498

499-
// crop image
500-
crop () {
499+
// get cropped canvas
500+
getCroppedCanvas () {
501501
const img = findDOMNode(this.img)
502-
let canvas = document.createElement('canvas')
502+
const canvas = document.createElement('canvas')
503503
const {
504504
x,
505505
y,
@@ -510,6 +510,13 @@ class Cropper extends Component {
510510
canvas.width = width
511511
canvas.height = height
512512
canvas.getContext('2d').drawImage(img, x, y, width, height, 0, 0, width, height)
513+
return canvas
514+
}
515+
516+
// crop image
517+
crop () {
518+
const canvas = this.getCroppedCanvas()
519+
513520
return canvas.toDataURL()
514521
}
515522

dist/app.js

Lines changed: 34 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/Cropper.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -540,11 +540,11 @@ var Cropper = function (_Component) {
540540
}
541541
}
542542

543-
// crop image
543+
// get cropped canvas
544544

545545
}, {
546-
key: 'crop',
547-
value: function crop() {
546+
key: 'getCroppedCanvas',
547+
value: function getCroppedCanvas() {
548548
var img = findDOMNode(this.img);
549549
var canvas = document.createElement('canvas');
550550
var _values$original = this.values().original,
@@ -557,6 +557,16 @@ var Cropper = function (_Component) {
557557
canvas.width = width;
558558
canvas.height = height;
559559
canvas.getContext('2d').drawImage(img, x, y, width, height, 0, 0, width, height);
560+
return canvas;
561+
}
562+
563+
// crop image
564+
565+
}, {
566+
key: 'crop',
567+
value: function crop() {
568+
var canvas = this.getCroppedCanvas();
569+
560570
return canvas.toDataURL();
561571
}
562572

0 commit comments

Comments
 (0)