1

I'm trying to build an application with fabric.js on node server. I followed the documented steps and i was able to set the canvas and fabric modules.

When i tried to include support for jpeg files by updating the binding.gyp file, the node.canvas breaks.

Current Configuration

v8: '5.1.281.83'
node@6.6.0
node-gyp@3.8.0
npm: '6.4.0-next.0'

Canvas pre-requisite versions

GTK - gtk+-bundle_2.22.1-20101229_win64
jpeglib - libjpeg-turbo-2.0.0-vc64

Installation Steps

npm i canvas

canvas project builds successfully without any errors

I updated binding.gyp in "node_modules/canvas" folder with the following

'with_jpeg%': 'true', 
'libjpeg_root%': 'C:/libjpeg-turbo64',

updated the condition

['with_jpeg=="true"', {
  'defines': [
    'HAVE_JPEG'
  ],
  'conditions': [
    ['OS=="win"', {
     'copies': [{
        'destination': '<(PRODUCT_DIR)',
        'files': [
          '<(libjpeg_root)/bin/jpeg62.dll',
        ]
      }],
      'libraries': [
         '-l<(libjpeg_root)/lib/jpeg.lib'
      ],
      'include_dirs': [
        '<(libjpeg_root)/include'
      ]
    }, {
      'libraries': [
        '-ljpeg'
      ]
    }]
  ]
}]

after updating the binding file node-gyp rebuild works fine without any issues and once done if i run the test

Test Canvas Code

var Canvas = require('canvas');

On running the test code i get the following error

Error: The specified module could not be found.
\\?\C:\<AppPath>\node_modules\canvas\build\Release\canvas.node
    at Error (native)

If i set with_jpeg variable to false and rebuild the test code works fine without any issue. I'm not quite sure about where i'm going wrong. Can somebody please help me to get this issue resolved.

Naveen
  • 121
  • 2
  • 7

1 Answers1

0

JPEG support on Windows requires node-canvas 2.x, and fabric.js uses 1.6.x currently. There are other source code changes required besides the build config changes that you made (see https://github.com/Automattic/node-canvas/pull/841/files#diff-b92a52ffb02b7fb42c340919b0f983d6).

You can save as a PNG until fabric.js upgrades, possibly using another tool to convert the PNG to a JPEG if you really want a JPEG.

ZachB
  • 13,051
  • 4
  • 61
  • 89