chartjs-node icon indicating copy to clipboard operation
chartjs-node copied to clipboard

Not being able to generate jpeg files

Open joaobarcia opened this issue 6 years ago • 1 comments

Hi,

Thanks for the great lib. I'm able to generate png's without any issue but I need to generate jpegs. My code is:

        var chartNode = new ChartjsNode(600, 600);
        let graphPNG = chartNode
          .drawChart(riepilogoGraph1Config)
          .then(() => {
            // chart is created

            // get image as png buffer
            return chartNode.getImageStream("image/png");
          })

If I change return chartNode.getImageStream("image/png"); to return chartNode.getImageStream("image/jpeg");

I get the following error:

C:\Users\barcia\Desktop\internal-api\node_modules\canvas\lib\jpegstream.js:44
    canvas[method](options.bufsize, options.quality, options.progressive, function(err, chunk){
                  ^

TypeError: canvas[method] is not a function
    at C:\Users\barcia\Desktop\internal-api\node_modules\canvas\lib\jpegstream.js:44:19
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickCallback (internal/process/next_tick.js:180:9)

Any tips on what I might be doing wrong?

Thanks

joaobarcia avatar Apr 19 '18 18:04 joaobarcia

I don't think jpeg images are really supported. I wrote this a while back but the fact that the test suite doesn't try image/jpeg tells me that it probably never really worked. Also windows, Cairo/Canvas has always had some weirdness.

sedouard avatar Apr 27 '18 21:04 sedouard