mirror of
https://github.com/konvajs/konva.git
synced 2025-09-18 18:27:58 +08:00
fix image size detection on zero values. fix #774
This commit is contained in:
@@ -5,6 +5,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
|
|
||||||
## Not released:
|
## Not released:
|
||||||
|
|
||||||
|
* Add ability to use `width = 0` and `height = 0` for `Konva.Image`.
|
||||||
|
|
||||||
## 4.1.0 - 2019-12-23
|
## 4.1.0 - 2019-12-23
|
||||||
|
|
||||||
* Make events work on some CSS transforms
|
* Make events work on some CSS transforms
|
||||||
|
@@ -92,11 +92,11 @@ export class Image extends Shape<ImageConfig> {
|
|||||||
}
|
}
|
||||||
getWidth() {
|
getWidth() {
|
||||||
var image = this.image();
|
var image = this.image();
|
||||||
return this.attrs.width || (image ? image.width : 0);
|
return this.attrs.width ?? (image ? image.width : 0);
|
||||||
}
|
}
|
||||||
getHeight() {
|
getHeight() {
|
||||||
var image = this.image();
|
var image = this.image();
|
||||||
return this.attrs.height || (image ? image.height : 0);
|
return this.attrs.height ?? (image ? image.height : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -368,4 +368,23 @@ suite('Image', function() {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test.only('check zero values', function(done) {
|
||||||
|
var stage = addStage();
|
||||||
|
var layer = new Konva.Layer();
|
||||||
|
stage.add(layer);
|
||||||
|
var src = 'assets/darth-vader.jpg';
|
||||||
|
Konva.Image.fromURL(src, function(image) {
|
||||||
|
layer.add(image);
|
||||||
|
layer.draw();
|
||||||
|
|
||||||
|
image.width(0);
|
||||||
|
image.height(0);
|
||||||
|
layer.draw();
|
||||||
|
|
||||||
|
assert.equal(image.width(), 0);
|
||||||
|
assert.equal(image.height(), 0);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user