QR Code Generator Implementation for Website

Our company is engaged in the development, support and maintenance of sites of any complexity. From simple one-page sites to large-scale cluster systems built on micro services. Experience of developers is confirmed by certificates from vendors.
Development and maintenance of all types of websites:
Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Our competencies:
Development stages
Latest works
  • image_website-b2b-advance_0.png
    B2B ADVANCE company website development
    1215
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1161
  • image_websites_belfingroup_462_0.webp
    Website development for BELFINGROUP
    852
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1043
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    823
  • image_bitrix-bitrix-24-1c_fixper_448_0.png
    Website development for FIXPER company
    815

QR Code Generator Implementation

QR codes are needed in personal cabinets (profile link), payment systems (QR for transfer), e-tickets, business cards, and marketing tools. Client-side generation without server requests is fast and doesn't depend on external services.

qrcode Library

qrcode is a reliable library with Canvas, SVG, and Data URL support. Works in both browser and Node.js.

npm install qrcode
npm install -D @types/qrcode

Generator Component

import QRCode from 'qrcode'
import { useEffect, useRef, useState } from 'react'

interface QRGeneratorProps {
  value: string
  size?: number
  errorCorrection?: 'L' | 'M' | 'Q' | 'H'
  color?: { dark: string; light: string }
}

export function QRGenerator({
  value,
  size = 256,
  errorCorrection = 'M',
  color = { dark: '#000000', light: '#ffffff' },
}: QRGeneratorProps) {
  const canvasRef = useRef<HTMLCanvasElement>(null)
  const [dataUrl, setDataUrl] = useState<string>('')

  useEffect(() => {
    if (!value || !canvasRef.current) return

    QRCode.toCanvas(canvasRef.current, value, {
      width: size,
      margin: 2,
      errorCorrectionLevel: errorCorrection,
      color,
    })

    // Prepare Data URL for download in parallel
    QRCode.toDataURL(value, {
      width: size * 2, // 2x for print clarity
      margin: 2,
      errorCorrectionLevel: errorCorrection,
      color,
    }).then(setDataUrl)
  }, [value, size, errorCorrection, color])

  function download() {
    const a = document.createElement('a')
    a.href = dataUrl
    a.download = 'qrcode.png'
    a.click()
  }

  return (
    <div className="flex flex-col items-center gap-3">
      <canvas ref={canvasRef} className="rounded" />
      {dataUrl && (
        <button onClick={download} className="text-sm text-blue-600 hover:underline">
          Download PNG
        </button>
      )}
    </div>
  )
}

SVG version for embedding in page

import QRCode from 'qrcode'
import { useState, useEffect } from 'react'

function QRCodeSVG({ value, size = 200 }: { value: string; size?: number }) {
  const [svg, setSvg] = useState<string>('')

  useEffect(() => {
    QRCode.toString(value, { type: 'svg', width: size, margin: 1 })
      .then(setSvg)
  }, [value, size])

  return (
    <div
      dangerouslySetInnerHTML={{ __html: svg }}
      className="inline-block"
    />
  )
}

SVG scales without quality loss — suitable for PDF and print materials.

QR with logo in center

QR code with H error correction level withstands up to 30% covered area — you can embed a logo:

async function generateQRWithLogo(text: string, logoUrl: string): Promise<string> {
  const canvas = document.createElement('canvas')
  const size = 400

  await QRCode.toCanvas(canvas, text, {
    width: size,
    margin: 2,
    errorCorrectionLevel: 'H', // Must be H with logo
    color: { dark: '#000000', light: '#ffffff' },
  })

  const ctx = canvas.getContext('2d')!

  const logo = new Image()
  logo.crossOrigin = 'anonymous'
  await new Promise<void>((resolve) => {
    logo.onload = () => resolve()
    logo.src = logoUrl
  })

  const logoSize = size * 0.18 // 18% of QR size
  const logoX = (size - logoSize) / 2
  const logoY = (size - logoSize) / 2

  // White background under logo
  ctx.fillStyle = '#ffffff'
  ctx.beginPath()
  ctx.roundRect(logoX - 4, logoY - 4, logoSize + 8, logoSize + 8, 6)
  ctx.fill()

  ctx.drawImage(logo, logoX, logoY, logoSize, logoSize)

  return canvas.toDataURL('image/png')
}

Server-side generation (Node.js)

When QR needs to be embedded in PDF or sent in email:

import QRCode from 'qrcode'

// Express / Next.js API route
export async function GET(request: Request) {
  const { searchParams } = new URL(request.url)
  const text = searchParams.get('text')

  if (!text) return new Response('Missing text', { status: 400 })

  const buffer = await QRCode.toBuffer(text, {
    type: 'png',
    width: 400,
    errorCorrectionLevel: 'M',
  })

  return new Response(buffer, {
    headers: {
      'Content-Type': 'image/png',
      'Cache-Control': 'public, max-age=3600',
    },
  })
}

What we do

Integrate QR generator in needed place (form, product card, personal cabinet), configure size, color, error correction level, optionally add logo and download to PNG/SVG.

Timeline: 0.5 day.