Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix interaction between resize filter and normal filter #5346

Merged
merged 1 commit into from
Oct 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/shapes/image.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,16 @@
this._element = element;
this._originalElement = element;
this._initConfig(options);
if (this.resizeFilter) {
this.applyResizeFilters();
}
if (this.filters.length !== 0) {
this.applyFilters();
}
// resizeFilters work on the already filtered copy.
// we need to apply resizeFilters AFTER normal filters.
// applyResizeFilters is run more often than normal fiters
// and is triggered by user interactions rather than dev code
if (this.resizeFilter) {
this.applyResizeFilters();
}
return this;
},

Expand Down
23 changes: 22 additions & 1 deletion test/unit/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
return element;
}


var IMG_SRC = fabric.isLikelyNode ? (__dirname + '/../fixtures/test_image.gif') : getAbsolutePath('../fixtures/test_image.gif'),
IMG_WIDTH = 276,
IMG_HEIGHT = 110;
Expand Down Expand Up @@ -184,6 +183,28 @@
});
});

QUnit.test('toObject with normal filter and resize filter', function(assert) {
var done = assert.async();
createImageObject(function(image) {
var filter = new fabric.Image.filters.Resize({resizeType: 'bilinear' });
image.resizeFilter = filter;
var filterBg = new fabric.Image.filters.Brightness({ brightness: 0.8 });
image.filters = [filterBg];
image.scaleX = 0.3;
image.scaleY = 0.3;
var toObject = image.toObject();
assert.deepEqual(toObject.resizeFilter, filter.toObject(), 'the filter is in object form now');
assert.deepEqual(toObject.filters[0], filterBg.toObject(), 'the filter is in object form now brightness');
fabric.Image.fromObject(toObject, function(imageFromObject) {
var filterFromObj = imageFromObject.resizeFilter;
var brightnessFromObj = imageFromObject.filters[0];
assert.ok(filterFromObj instanceof fabric.Image.filters.Resize, 'should inherit from fabric.Image.filters.Resize');
assert.ok(brightnessFromObj instanceof fabric.Image.filters.Brightness, 'should inherit from fabric.Image.filters.Resize');
done();
});
});
});

QUnit.test('toObject with applied resize filter', function(assert) {
var done = assert.async();
createImageObject(function(image) {
Expand Down