Skip to content

Commit

Permalink
cleaned up some cropping logic in Image, and added a cropping unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
ericdrowell committed Dec 1, 2012
1 parent 047e263 commit 8a19561
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 9 deletions.
12 changes: 5 additions & 7 deletions src/Shape.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/shapes/Image.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
Loading

0 comments on commit 8a19561

Please sign in to comment.