cleaned up some cropping logic in Image, and added a cropping unit test

This commit is contained in:
Eric Rowell
2012-11-30 20:01:10 -08:00
parent 047e26382e
commit 8a195618cf
4 changed files with 37 additions and 9 deletions

View File

@@ -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();

View File

@@ -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];