Questions tagged [node-canvas]

Node canvas is a Cairo backed Canvas implementation for NodeJS.

Installation

$ npm install canvas

node-canvas extends the canvas API to provide interfacing with node, for example streaming PNG data, converting to a Buffer instance, etc. Among the interfacing API, in some cases the drawing API has been extended for SSJS image manipulation / creation usage, however keep in mind these additions may fail to render properly within browsers.

Github

Node Wiki

152 questions
4
votes
1 answer

Node Canvas on Vercel Serverless Function - The Serverless Function exceeds the maximum size limit of 50mb

I'm generating images on the server based on data users send to the API route I have in Next.js using the canvas package. It's working great, but I am unable to deploy the project to Vercel as the canvas dependency is too big (44.9 MB compressed…
Jarrod Watts
  • 345
  • 3
  • 13
4
votes
1 answer

Center Text with Multi Lines on Canvas in NodeJS

I want to center text on a canvas. Horizontally seems fine, but vertical is still a problem: I cannot figure out how to programmatically do this. I was previously able to do this with 1 line, but now I'd like to get it to work for multiple lines of…
userjmillohara
  • 457
  • 5
  • 25
4
votes
1 answer

How to use custom font with paper-jsdom-canvas

I am building a node-canvas 2d library using paper-jsdom-canvas. PaperJS is failing to use my custom fonts that I am registering using registerFont method of canvas. But when I try to use the canvas project directly, the font is rendered without any…
Rashid Shaikh
  • 395
  • 4
  • 12
4
votes
1 answer

Node.js - Download & process Image with 'request' and 'node-canvas'

I'm using the request and node-canvas modules to try and download and process an image: var request = require('request'); var Image = require('canvas').Image; var url =…
Sunday Ironfoot
  • 12,840
  • 15
  • 75
  • 91
4
votes
1 answer

Convert png image to pdf in nodejs canvas

I need to create a pdf from canvas. can any body help me ? this is what i tried var http = require('http'), fs = require('fs'), Canvas = require('canvas'); var ht = require('https'); http.createServer(function (req, res) { dr(); function dr() { …
SHIN
  • 386
  • 2
  • 13
3
votes
2 answers

Unable to install node-canvas on M1 mac

Need help getting node-canvas installed with on an M1 mac. Here is the log. yarn install ... ➤ YN0000: ┌ Link step ➤ YN0007: │ canvas@npm:2.10.1 must be built because it never has been before or the last one failed ➤ YN0009: │ canvas@npm:2.10.1…
a11hard
  • 1,904
  • 4
  • 19
  • 41
3
votes
0 answers

Nodejs installing node-canvas on ubuntu not working. Error: "internal/modules/cjs/loader.js:1122 "

I tried to install nodejs canvas on my ubuntu 18.04.5 vm. I am using nodejs v14.16.0 installed using the snap package manager. Following the instructions on the GitHub wiki from…
Clafter
  • 78
  • 5
3
votes
2 answers

Problem with canvas using vega with nodejs (server side only)

I've been working for a few weeks now on a Discord bot that basically compiles stats on the server and deduces patterns. In order to improve it, I wanted to make it generate graphs as PNGs in order to send them back to the user - in short, no…
Ruben N
  • 43
  • 8
3
votes
4 answers

node-canvas registerFont can't find font file once deployed (works locally)

I have a Node.js server that uses node-canvas to render text on an image on the server-side. Here is the repo: https://github.com/shawninder/meme-generator (just git clone, npm i and npm run dev to run locally). As you'll notice in the code, I am…
Shawn
  • 10,931
  • 18
  • 81
  • 126
3
votes
1 answer

Asynchronously writing files in a loop, how to manage streams

I am trying to write over 100 png files via node-canvas in a loop. Only 40 files get generated and then the process completes. I have tried creating a png stream via createPNGStream() and piping the results to a write stream created by…
afriedman111
  • 1,925
  • 4
  • 25
  • 42
3
votes
2 answers

How do I image snapshot test a React component using HTML5 canvas?

I'm attempting to get image snapshot testing working (i.e., not mocked) with a React component that renders an HTML5 canvas. I'm using Jest, React Testing Library, Node Canvas, Puppeteer, and Jest Image Snapshot. Given the following React…
icfantv
  • 4,523
  • 7
  • 36
  • 53
3
votes
2 answers

Convert base64 png to jpeg image in Nodejs

I am using FabricJS module in Nodejs. There is a Canvas I am trying to export as jpeg but it wont(giving me a hard time). All I am getting is base64 png data. Data that starts like data:image/png;base64,…
Abhinav
  • 8,028
  • 12
  • 48
  • 89
3
votes
1 answer

Using node-canvas in a Lambda function?

I'm trying to use node-canvas to create animated gifs with an AWS Lambda function. But I'm struggling to even get off the ground with all the dependencies. I've read the thread here, but it's mostly greek and I can't get it working. I'd far prefer…
nicholas
  • 14,184
  • 22
  • 82
  • 138
3
votes
2 answers

node-canvas build for AWS Lambda

I'm a Linux & node noob. I'm trying to run FabricJS (which requires node-canvas) in AWS Lambda. I've been able to follow the instructions to get up and running on an AWS Linux EC2, however, Lambda has me at my wits end. Anyone have any tips or…
jDud
  • 31
  • 3
3
votes
1 answer

Find primary/dominant color of an image with canvas

I am new to node.js. I´ve read the thread about Node.js Image Libraries and it seems that GM seems to be the most advanced. I am trying to find out the most dominant color of an image using nodejs. Then I have found this script color-thief , which…
zer02
  • 3,963
  • 4
  • 31
  • 66
1
2
3
10 11