-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Filters don't apply after load canvas from JSON #365
Comments
Just found fabric.Image.prototype.initialize() call fabric.Image.prototype.applyFilter() without passing callback and if isLikelyNode is false, the replacement image maked by the filter is replaced asynchronously. Si, hard to fix without passing callback arg to fabric.Image.prototype.initialize, maybe it would be necessary.to use a Deferred object like jQuery does. |
Note there is a standalone implementation of $.Deferred : https://github.com/warpdesign/Standalone-Deferred |
The way I implemented this in our app is along these lines: canvas.loadFromDatalessJSON(json, function() {
applyImageFilters(); and applyImageFilters: function() {
canvas.forEachObject(function(obj) {
if (obj.type === 'image' && obj.filters.length) {
obj.applyFilters(function() {
obj.canvas.renderAll();
});
}
});
} Not sure if this should be part of |
With this code, the canvas is rendered for each image object which has filter, instead of only at the end of all filters applied, no ? fcanvas.loadFromJSON($('#saved').val(), function () {
var objLen = fcanvas.getObjects().length;
var renderIfAll = function () {
if (--objLen == 0) {
fcanvas.renderAll();
}
};
fcanvas.forEachObject(function(obj) {
if (obj.type === 'image' && obj.filters.length) {
obj.applyFilters(renderIfAll);
} else {
renderIfAll();
}
});
}); But an other issue is that the filters are applied 2 times in this case, once in fabric.Image.prototype.initialize and once here, and the rendering too. |
Possible solutions:
Sent from my iPhone On Dec 30, 2012, at 23:06, xxorax [email protected] wrote:
|
This ugly fix solves the problem for anyone lurking: $(window).on('load', function() {
canvas.renderAll();
}); |
Came across this old chestnut again today. Any progress on this? Need a solution that works as things are right now even if it is not optimal regarding render calls. |
For now I am using: setTimeout(function() {
canvas.renderAll();
}, 2000); In the callback for |
I am using the following:
|
How to apply resize filters(lanczos etc...) in loadFromJSON()? |
I made this: |
When you save and load the canvas in JSON, the filters on the objects don't be apply until you call an async renderAll on the canvas, by refreshing it with canvas.renderAll() or by clicking inside the canvas.
See an exemple :
http://www.xorax.info/labs/misc/canvas/fabricjs-issue-loadAndFilter.php
Apply the greyscale filter, click save to save the JSON in the input, and
It seems there is an async break somewhere.
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
The text was updated successfully, but these errors were encountered: