You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
By default, binaries for macOS, Linux and Windows will be downloaded.
But if you don't have a supported OS or processor architecture the module will be compiled on your system.
This requires several dependencies from node-canvas, you must install Cairo and Pango.
Instructions on how to do this are provided in the node-canvas wiki.
// Load in our dependenciesvarCanvassmith=require('canvassmith');// Create a new enginevarcanvassmith=newCanvassmith();// Interpret some images from diskcanvassmith.createImages(['img1.jpg','img2.png'],functionhandleImages(err,imgs){// If there was an error, throw itif(err){throwerr;}// We recieve images in the same order they were givenimgs[0].width;// 50 (pixels)imgs[0].height;// 100 (pixels)// Create a canvas that fits our images (200px wide, 300px tall)varcanvas=canvassmith.createCanvas(200,300);// Add the images to our canvas (at x=0, y=0 and x=50, y=100 respectively)canvas.addImage(imgs[0],0,0);canvas.addImage(imgs[1],50,100);// Export canvas to imagevarresultStream=canvas['export']({format: 'png'});resultStream;// Readable stream outputting PNG image of the canvas});
Documentation
This module was built to the specification for spritesmith engines.
Our createImages methods supports the following types of images:
image String - Filepath to image
image Object - Vinyl object with buffer for image (uses buffer)
image Object - Vinyl object with stream for image (uses stream)
image Object - Vinyl object with null for image (reads buffer from provided filepath)
Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint using npm run lint and test via npm test.