PHP 8.2.30
Preview: canvas.js Size: 1.47 KB
//proc/thread-self/root/home/byroehnu/.trash/node_modules11/qrcode/lib/renderer/canvas.js

const Utils = require('./utils')

function clearCanvas (ctx, canvas, size) {
  ctx.clearRect(0, 0, canvas.width, canvas.height)

  if (!canvas.style) canvas.style = {}
  canvas.height = size
  canvas.width = size
  canvas.style.height = size + 'px'
  canvas.style.width = size + 'px'
}

function getCanvasElement () {
  try {
    return document.createElement('canvas')
  } catch (e) {
    throw new Error('You need to specify a canvas element')
  }
}

exports.render = function render (qrData, canvas, options) {
  let opts = options
  let canvasEl = canvas

  if (typeof opts === 'undefined' && (!canvas || !canvas.getContext)) {
    opts = canvas
    canvas = undefined
  }

  if (!canvas) {
    canvasEl = getCanvasElement()
  }

  opts = Utils.getOptions(opts)
  const size = Utils.getImageWidth(qrData.modules.size, opts)

  const ctx = canvasEl.getContext('2d')
  const image = ctx.createImageData(size, size)
  Utils.qrToImageData(image.data, qrData, opts)

  clearCanvas(ctx, canvasEl, size)
  ctx.putImageData(image, 0, 0)

  return canvasEl
}

exports.renderToDataURL = function renderToDataURL (qrData, canvas, options) {
  let opts = options

  if (typeof opts === 'undefined' && (!canvas || !canvas.getContext)) {
    opts = canvas
    canvas = undefined
  }

  if (!opts) opts = {}

  const canvasEl = exports.render(qrData, canvas, opts)

  const type = opts.type || 'image/png'
  const rendererOpts = opts.rendererOpts || {}

  return canvasEl.toDataURL(type, rendererOpts.quality)
}

Directory Contents

Dirs: 1 × Files: 7

Name Size Perms Modified Actions
terminal DIR
- drwxr-xr-x 2026-02-27 09:45:04
Edit Download
1.47 KB lrw-r--r-- 2026-02-27 09:45:00
Edit Download
1.73 KB lrw-r--r-- 2026-02-27 09:45:00
Edit Download
1.92 KB lrw-r--r-- 2026-02-27 09:45:02
Edit Download
532 B lrw-r--r-- 2026-02-27 09:45:02
Edit Download
271 B lrw-r--r-- 2026-02-27 09:45:04
Edit Download
1.54 KB lrw-r--r-- 2026-02-27 09:45:04
Edit Download
2.83 KB lrw-r--r-- 2026-02-27 09:45:04
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).