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

[2.0] Node - Image filters not working #4231

Closed
jfizz opened this issue Aug 20, 2017 · 15 comments
Closed

[2.0] Node - Image filters not working #4231

jfizz opened this issue Aug 20, 2017 · 15 comments

Comments

@jfizz
Copy link

jfizz commented Aug 20, 2017

Version

Fabric 2.0.0-beta.6
Node v6.9.5

Test Case

var fabric = require('fabric').fabric;
var fs = require('fs');
var path = require('path');

fabric.Image.fromURL('http://fabricjs.com/assets/pug.jpg', function(image) {
  image.scaleToWidth(300);
  image.filters = [new fabric.Image.filters.Sepia()];
  image.applyFilters();

  var canvas = fabric.createCanvasForNode(300, 300, {backgroundColor: '#ffffff'});
  canvas.add(image);
  canvas.renderAll();

  let outputPath = path.join(__dirname, 'out.jpg');
  let file = fs.createWriteStream(outputPath);
  file.on('error', function(err) {
    console.log(err);
    process.exit(1);
  });
  file.on('finish', function() {
    console.log('wrote to', outputPath);
    process.exit();
  });

  canvas.createJPEGStream().pipe(file);
});
/Users/jFizz/Web/node-fabric/node_modules/fabric/dist/fabric.js:18811
      elementToDraw && ctx.drawImage(elementToDraw,
                           ^

TypeError: Image or Canvas expected
    at TypeError (native)
    at klass._render (/Users/jFizz/Web/node-fabric/node_modules/fabric/dist/fabric.js:18811:28)
    at klass.drawObject (/Users/jFizz/Web/node-fabric/node_modules/fabric/dist/fabric.js:12675:12)
    at klass.render (/Users/jFizz/Web/node-fabric/node_modules/fabric/dist/fabric.js:12623:14)
    at klass._renderObjects (/Users/jFizz/Web/node-fabric/node_modules/fabric/dist/fabric.js:7082:34)
    at klass.renderCanvas (/Users/jFizz/Web/node-fabric/node_modules/fabric/dist/fabric.js:7059:12)
    at klass.renderAll (/Users/jFizz/Web/node-fabric/node_modules/fabric/dist/fabric.js:8994:12)
    at /Users/jFizz/Web/node-fabric/index.js:12:10
    at /Users/jFizz/Web/node-fabric/node_modules/fabric/dist/fabric.js:18990:19
    at createImageAndCallBack (/Users/jFizz/Web/node-fabric/node_modules/fabric/dist/fabric.js:27554:30)

When filters are not applied, it works as expected. I attempted to create a cloud9 but I am not sure how to build fabric for their environment. If you have an existing workspace, I could try to use that.

@asturur
Copy link
Member

asturur commented Aug 31, 2017

Just to say i did not let this behind.
I m currently trying to understand why jsdom does not behave how it should, but my low expertise with fabric+node and jsdom makes everything harder.

So i'm trying to remove all specific node code since jsdom should handle the job quite well. The problem is that sometimes the canvas that is drawing is a pure node-canvas canvas, sometimes is JSDOM wrapped canvas.

and this thing makes it break.

@jfizz
Copy link
Author

jfizz commented Sep 27, 2017

@asturur Just wanted to provide an update on this one: I tried it with the latest release (2.0.0-beta.7) but experienced the same result.

@CombatCode
Copy link

It's killing me, anything new in this topic??

@asturur
Copy link
Member

asturur commented Nov 1, 2017

is hard for me too. in our case jsdom is not transparent with our filtering operation.
Almost all node specific code can be removed in 2.0 but filters fails because at some point we pass to drawImage a node canvas wrapped in jsdom and that makes it fails.

i ll try again and open an help request on jsdom and link it here.

@CombatCode
Copy link

@asturur thank you for the reply, can you say more what dirty hack have you used here #4257 to make it working ? I'm considering to fork JSDOM and place some temporary hack to fix this issue, but newest JSDOM is not supported by fabricjs... right now I feel like a blind child in the Bieszczady trying to fix that

@asturur
Copy link
Member

asturur commented Nov 1, 2017

i did not manage to fix filters. jsdom 9.x is way batter than the old 3.x
i would remove node 4 support and switch to jsdom 11.x if it would change something.

so jsdom is detecting node canvas support and is providing fabricjs with fake canvas elements that should just work.

and they work for everything except filters.

now i m out, i ll redo that branch and share it to give it a try.

@URSTYLE
Copy link

URSTYLE commented Nov 8, 2017

Any news here? or it's just to hard topic and we should back to 1.x version with our code

@asturur
Copy link
Member

asturur commented Nov 8, 2017

I'm sorry no news, i did not have time to handle this.

@asturur
Copy link
Member

asturur commented Nov 19, 2017

finally starting to investigate this.

@asturur
Copy link
Member

asturur commented Nov 19, 2017

Latest build fix filters in nodejs.

out

out2

@asturur asturur closed this as completed Nov 19, 2017
@qynAUGMN
Copy link

@asturur when use the 2.0-rc.1, canvas.createJPEGStream is undefined.What's your way to initiate a new fabric.Canvas?

@asturur
Copy link
Member

asturur commented Nov 24, 2017

i think you need to install libjpeg when you build node canvas

@qynAUGMN
Copy link

alreay installed,use 2.0.0-beta.7 is ok.

@asturur
Copy link
Member

asturur commented Nov 24, 2017

the error was called differently before because now is jsdom that is probably surfacing it.
Is a JSDOM or a node-canvas issue, nothing i can fix. i have the same error when i run tests

@qynAUGMN
Copy link

when updated 2.0.0-rc.3,i found canvas.createJPEGStream is a function,but no stream response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants