ushelp / EasyQRCodeJS-NodeJS

EasyQRCodeJS-NodeJS is a NodeJS server side javascript QRCode image(PNG/JPEG/SVG/Base64 data url) generator. Support setting Dot style, Logo, Background image, Colorful, Title and more. Support binary(hex) data mode.
http://www.easyproject.cn/easyqrcodejs/tryit.html
MIT License
98 stars 51 forks source link

Canvas dependency is too big to deploy on Vercel #37

Open kdubb1337 opened 1 year ago

kdubb1337 commented 1 year ago

As you can see from the screenshot, canvas alone is taking up more than 90% of the allowed size of Vercel's serverless functions. Would suggest moving to something more lightweight like: https://www.npmjs.com/package/@napi-rs/canvas

Vercel error

CleanShot 2023-02-09 at 21 12 45

My Serverless function

import { NextApiRequest, NextApiResponse } from 'next'
import nextConnect from 'next-connect'
import QRCode from 'easyqrcodejs-nodejs'

const handler = nextConnect().get(async (req: NextApiRequest, res: NextApiResponse) => {
  const options = {
    width: 400,
    height: 400,
    text: 'https://example.com',
    dotScale: 0.9,
  }

  const qrcode = new QRCode(options)
  const base64Data = (await qrcode.toDataURL()).replace('data:image/png;base64,', '')
  const img = Buffer.from(base64Data, 'base64')

  res.setHeader('Content-Type', 'image/png')
  res.setHeader('Content-Length', img.length)
  res.send(img)
})

export default handler
0xAnthony commented 9 months ago

Completely agree, same issue for deploying on any lambda, Canvas alone take all the free space