Browse Source

Set dimensions properly of images on initialization. (#3205)

* Set dimensions properly of images on initialization.

Fix for #3203

Image nodes were assigned the default size on initialization, leading to very compressed images.
This fix adjusts the default size as soon as the images used have been loaded.

The approach for dealing with this has been adapted from `CircularImage`.

* Fixed tabs
gemini
wimrijnders 7 years ago
committed by yotamberk
parent
commit
ff5916dc8e
2 changed files with 12 additions and 0 deletions
  1. +1
    -0
      lib/network/CachedImage.js
  2. +11
    -0
      lib/network/modules/components/nodes/shapes/Image.js

+ 1
- 0
lib/network/CachedImage.js View File

@ -23,6 +23,7 @@ class CachedImage {
init() { init() {
if (this.initialized()) return; if (this.initialized()) return;
this.src = this.image.src; // For same interface with Image
var w = this.image.width; var w = this.image.width;
var h = this.image.height; var h = this.image.height;

+ 11
- 0
lib/network/modules/components/nodes/shapes/Image.js View File

@ -10,6 +10,17 @@ class Image extends CircleImageBase {
} }
resize(ctx, selected = this.selected, hover = this.hover) { resize(ctx, selected = this.selected, hover = this.hover) {
var imageAbsent = (this.imageObj.src === undefined) ||
(this.imageObj.width === undefined) ||
(this.imageObj.height === undefined);
if (imageAbsent) {
var side = this.options.size * 2;
this.width = side;
this.height = side;
return;
}
if (this.needsRefresh(selected, hover)) { if (this.needsRefresh(selected, hover)) {
this._resizeImage(); this._resizeImage();
} }

Loading…
Cancel
Save