diff --git a/src/shapes/image.class.js b/src/shapes/image.class.js index 4e165635171..584116e4297 100644 --- a/src/shapes/image.class.js +++ b/src/shapes/image.class.js @@ -206,7 +206,6 @@ */ toObject: function(propertiesToInclude) { var filters = [ ], resizeFilters = [ ], - element = this._originalElement, scaleX = 1, scaleY = 1; this.filters.forEach(function(filterObj) { @@ -224,7 +223,7 @@ }); var object = extend(this.callSuper('toObject', propertiesToInclude), { - src: element ? element.src || element._src : '', + src: this.getSrc(), filters: filters, resizeFilters: resizeFilters, crossOrigin: this.crossOrigin, @@ -297,8 +296,12 @@ * @return {String} Source of an image */ getSrc: function() { - if (this.getElement()) { - return this.getElement().src || this.getElement()._src; + var element = this.getElement(); + if (element) { + return fabric.isLikelyNode ? element._src : element.src; + } + else { + return this.src || ''; } }, diff --git a/test/unit/canvas_static.js b/test/unit/canvas_static.js index 306f1ccb308..a2d25174c0e 100644 --- a/test/unit/canvas_static.js +++ b/test/unit/canvas_static.js @@ -75,7 +75,7 @@ 'flipX': false, 'flipY': false, 'opacity': 1, - 'src': fabric.isLikelyNode ? undefined : IMG_SRC, + 'src': IMG_SRC, 'shadow': null, 'visible': true, 'backgroundColor': '', @@ -115,6 +115,7 @@ require('fs').readFile(src, function(err, imgData) { if (err) throw err; img.src = imgData; + img._src = src; callback && callback(); }); } diff --git a/test/unit/image.js b/test/unit/image.js index 84410de09e2..d5c6c5eae78 100644 --- a/test/unit/image.js +++ b/test/unit/image.js @@ -35,7 +35,7 @@ 'flipX': false, 'flipY': false, 'opacity': 1, - 'src': fabric.isLikelyNode ? undefined : IMG_SRC, + 'src': IMG_SRC, 'shadow': null, 'visible': true, 'backgroundColor': '', @@ -79,6 +79,7 @@ require('fs').readFile(src, function(err, imgData) { if (err) throw err; img.src = imgData; + img._src = src; callback && callback(); }); } @@ -131,7 +132,7 @@ if (toObject.height === 0) { toObject.height = IMG_HEIGHT; } - deepEqual(toObject, fabric.util.object.extend(REFERENCE_IMG_OBJECT, {src: ''})); + deepEqual(toObject, REFERENCE_IMG_OBJECT); start(); }); }); @@ -212,7 +213,7 @@ asyncTest('toString', function() { createImageObject(function(image) { ok(typeof image.toString == 'function'); - equal(image.toString(), '#'); + equal(image.toString(), '#'); start(); }); }); @@ -220,7 +221,7 @@ asyncTest('getSrc', function() { createImageObject(function(image) { ok(typeof image.getSrc == 'function'); - equal(image.getSrc(), fabric.isLikelyNode ? undefined : IMG_SRC); + equal(image.getSrc(), IMG_SRC); start(); }); });