image-to-slices icon indicating copy to clipboard operation
image-to-slices copied to clipboard

Error: Require node-canvas on the server-side Node.js

Open llgdd opened this issue 5 years ago • 3 comments

So I have a Telegram bot that makes screenshots of a site with puppeteer, but they turn out too long, so I decided to slice them with image-to-slices. After installing both canvas and image-to-slices (image-clipper is present as well) when I run the script, it throws this error:

Error: Require node-canvas on the server-side Node.js
    at ImageClipper.__createImage (C:\Users\llgdd\Bots\node_modules\image-clipper\lib\clipper.js:456:13)
    at ImageClipper.loadImageFromUrl (C:\Users\llgdd\Bots\node_modules\image-clipper\lib\clipper.js:83:20)
    at ImageClipper.image (C:\Users\llgdd\Bots\node_modules\image-clipper\lib\clipper.js:120:10)
    at imageClipper (C:\Users\llgdd\Bots\node_modules\image-clipper\lib\index.js:36:15)
    at ImageToSlices.slice (C:\Users\llgdd\Bots\node_modules\image-to-slices\lib\image-to-slices.js:212:3)
    at ImageToSlicesFactory (C:\Users\llgdd\Bots\node_modules\image-to-slices\lib\index.js:22:17)

Can anyone help please? Would be cool to know what causes this.

llgdd avatar Oct 06 '19 10:10 llgdd

Before using do this: clipper.configure('canvas', canvas);

Source: https://www.npmjs.com/package/image-clipper#inject-node-canvas

alvarrus avatar Jan 11 '20 04:01 alvarrus

Thanks, I'll try that out!

llgdd avatar Jan 12 '20 08:01 llgdd

This is what you are looking for: var imageToSlices = require('image-to-slices'); After requiring image-to-slices you need to add this configuration:

imageToSlices.configure({
    clipperOptions: {
        canvas: require('canvas')
    }
});

stas4000 avatar Jul 28 '22 09:07 stas4000