image-to-slices
image-to-slices copied to clipboard
Error: Require node-canvas on the server-side Node.js
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.
Before using do this: clipper.configure('canvas', canvas);
Source: https://www.npmjs.com/package/image-clipper#inject-node-canvas
Thanks, I'll try that out!
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')
}
});