How to enable jpeg support in node-canvas on x64 windows using MSVC10 compiler?

I need to display jpeg images on nodejs serverside. I install the npm canvas module with the following assembly instructions: https://github.com/Automattic/node-canvas/wiki/Installation---Windows I have C: \ libjpeg-turbo \, as indicated in the manual. If I do this:

npm install canvas

then this piece of code does not start at boot:

var data = fs.readFileSync("./t.jpg"); var img = new Image(); img.onload = function () { console.log("onload"); }; img.src = data; 

(it works with .png data). If I specify --with-jpeg on my command line, then MSVC complains about the lack of libjpeg.h. Immediately after this, npm deletes the file with the msvc project, so I canโ€™t set the paths myself (can I disable this cleanup?)

So how can I create a canvas for windows with jpeg support? Questions found, but no answers to this topic on the net.

+8
windows npm node-canvas
source share
2 answers

It seems to me that binding.gyp does not have the include_dirs directive in line # 143, so the compiler can find libjpeg.h in the C: \ libjpeg-turbo \ directory. Try pasting:

  'include_dirs': [ 'c:/libjpeg-turbo', ], 
0
source share

Install MSVC10 and 64-bit nodes. When your build fails, use the following distributions that you find on the network:

  • unzip gtk + -bundle_2.22.1-20101229_win64.zip to c: / gtk. Use this version, others I failed

  • setup libjpeg-turbo-1.4.0-vc64.exe for C: \ libjpeg-turbo (32bit libs will not work without a meaningful message)

  • go to. \ node_modules \ canvas \ build \ and change your binding.gyp. Add 'Variables':
  { 'GTK_Root%': 'C:/GTK', # Set the location of GTK all-in-one bundle 'with_jpeg%': 'true', 'libjpeg_root%':'C:/libjpeg-turbo', 'with_gif%': 'false', 'with_pango%': 'false', 'with_freetype%': 'false' } 

and

 ['with_jpeg=="true"', { 'defines': [ 'HAVE_JPEG' ], 'conditions': [ ['OS=="win"', { 'libraries': [ '-l<(libjpeg_root)/lib/jpeg-static.lib','-l<(libjpeg_root)/lib/jpeg.lib' ], 'include_dirs': [ '<(libjpeg_root)/include' ] }, { 'libraries': [ '-ljpeg' ] }] ] }] 

then run the following commands in the folder where the .gyp file is located:

node -gyp configure

node -gyp build

IMHO libraries for such modules should be included in npm distributions, it is strange to expect WIN32 / C ++ experience from nodejs programmer ...

+3
source share

All Articles