mirror of
https://github.com/konvajs/konva.git
synced 2025-10-15 12:34:52 +08:00
cleaned up some cropping logic in Image, and added a cropping unit test
This commit is contained in:
12
src/Shape.js
12
src/Shape.js
@@ -174,13 +174,11 @@
|
||||
context.save();
|
||||
var a = Array.prototype.slice.call(arguments);
|
||||
|
||||
if(a.length === 6 || a.length === 10) {
|
||||
if(a.length === 6) {
|
||||
context.drawImage(a[1], a[2], a[3], a[4], a[5]);
|
||||
}
|
||||
else {
|
||||
context.drawImage(a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9]);
|
||||
}
|
||||
if(a.length === 6) {
|
||||
context.drawImage(a[1], a[2], a[3], a[4], a[5]);
|
||||
}
|
||||
else if(a.length === 10) {
|
||||
context.drawImage(a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9]);
|
||||
}
|
||||
|
||||
context.restore();
|
||||
|
@@ -38,8 +38,8 @@ Kinetic.Image.prototype = {
|
||||
if(this.attrs.image) {
|
||||
// if cropping
|
||||
if(this.attrs.crop && this.attrs.crop.width && this.attrs.crop.height) {
|
||||
var cropX = this.attrs.crop.x ? this.attrs.crop.x : 0;
|
||||
var cropY = this.attrs.crop.y ? this.attrs.crop.y : 0;
|
||||
var cropX = this.attrs.crop.x || 0;
|
||||
var cropY = this.attrs.crop.y || 0;
|
||||
var cropWidth = this.attrs.crop.width;
|
||||
var cropHeight = this.attrs.crop.height;
|
||||
params = [context, this.attrs.image, cropX, cropY, cropWidth, cropHeight, 0, 0, width, height];
|
||||
|
Reference in New Issue
Block a user