mirror of
https://github.com/konvajs/konva.git
synced 2025-06-28 15:23:44 +08:00
cleaned up some cropping logic in Image, and added a cropping unit test
This commit is contained in:
parent
047e26382e
commit
8a195618cf
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];
|
||||
|
File diff suppressed because one or more lines are too long
@ -121,6 +121,35 @@ Test.Modules.IMAGE = {
|
||||
};
|
||||
imageObj.src = '../assets/darth-vader.jpg';
|
||||
},
|
||||
'crop add and scale image': function(containerId) {
|
||||
var imageObj = new Image();
|
||||
imageObj.onload = function() {
|
||||
var stage = new Kinetic.Stage({
|
||||
container: containerId,
|
||||
width: 578,
|
||||
height: 200
|
||||
});
|
||||
var layer = new Kinetic.Layer();
|
||||
darth = new Kinetic.Image({
|
||||
x: 200,
|
||||
y: 75,
|
||||
image: imageObj,
|
||||
width: 107,
|
||||
height: 75,
|
||||
crop: [186, 211, 292 - 186, 285 - 211],
|
||||
draggable: true,
|
||||
scale: [0.5, 0.5]
|
||||
});
|
||||
|
||||
layer.add(darth);
|
||||
stage.add(layer);
|
||||
|
||||
//console.log(layer.toDataURL());
|
||||
|
||||
warn(layer.toDataURL() === dataUrls['crop and scale image'], 'problem rendering cropped and scaled image');
|
||||
};
|
||||
imageObj.src = '../assets/darth-vader.jpg';
|
||||
},
|
||||
'create image hit region': function(containerId) {
|
||||
var imageObj = new Image();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user