Coder Social home page Coder Social logo

davidje13 / lean-qr Goto Github PK

View Code? Open in Web Editor NEW
11.0 11.0 1.0 820 KB

Minimal library for generating QR codes in the browser and server-side.

Home Page: https://qr.davidje13.com/

License: MIT License

JavaScript 60.60% HTML 33.99% CSS 3.09% Shell 0.47% TypeScript 1.84%

lean-qr's People

Contributors

davidje13 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

passiontim

lean-qr's Issues

SVG output?

Great library with small footprint.

The only thing I'm missing is a renderer for SVG.

Any suggestions on how we could do this?

Download documentation

Hi,
when I look at the example to download a file, I feel like there is something missing.
https://qr.davidje13.com/docs/

<a href="#" download="qr.png" id="download-link">Download</a>

<script type="module">
  import { generate } from 'lean-qr';

  const code = generate('LEAN-QR LIBRARY');

  const dataUrl = qrCode.toDataURL({ scale: 10 });
  document.getElementById('download-link')
    .setAttribute('href', dataUrl);
</script>
  • Where does qrCode come from?
  • I don't think there is a function toDataURL on the returntype of generate

add toCanvas example to readme

The Readme is missing what element should be used in the html template.

I played around with a <div>.

Looking through your example website I found the element should be a canvas with width and height.

  • <canvas id="my-canvas" width="1" height="1"></canvas>

As someone who never used <canvas> before, this could be very helpful to include in the Readme.

I spent 3 hours on this.

Thank You!

output a larger canvas size?

Hi!

Thanks for the svg implementation, it's working great :)

I was having troubles generating a larger png file though.

as you have shown in the docs:

code.toCanvas(canvas)
a.href = canvas.toDataURL('image/png')

The problem with this is that the canvas size is fixed to x number of pixels depending on the complexity of the qr code.

I was able to work around it this way

// draw the qr code to a canvas
const canvas = document.createElement('canvas')
const code = generate('mytext')
code.toCanvas(canvas)

// create a second canvas to export a larger version
const outputCanvas = document.createElement('canvas')
outputCanvas.width = 1024
outputCanvas.height = 1024
const ctx = outputCanvas.getContext('2d')
// don't smooth when we scale up
ctx.imageSmoothingEnabled = false
// first we pass in the canvas and its size, then we pass in the size we want to resize to
ctx.drawImage(
  canvas,
  0,
  0,
  canvas.width,
  canvas.height,
  0,
  0,
  1024,
  1024,
)
return outputCanvas.toDataURL('image/png')

I don't know if you know of an easier way to scale the canvas up, or get a larger version of the qr code?

I though it might be good to add this to the docs :)

fix error "Cannot find module 'lean-qr/extras/svg'"

Description

I'm trying to add a QR Code in an vuejs app. Using the function toSvgDataURL will result in an console error:
Uncaught Error: Cannot find module 'lean-qr/extras/svg'

Usage

...

import { generate } from 'lean-qr'
import { toSvgDataURL } from 'lean-qr/extras/svg'

const code = generate(`https://qr.sli.do/${this.eventId}`)

const dataURL = toSvgDataURL(code, {
  on: 'black',
  off: 'transparent',
  padX: 4,
  padY: 4,
  width: null,
  height: null,
  scale: 1
})
console.log('dataURL', dataURL)

...

The same error occurrs for all methods relying on the import lean-qr/extras/svg

Full error message in browser console

cjs.js?!./node_modules/babel-loader/lib/index.js!./node_modules/cache-loader/dist/cjs.js?!./node_modules/vue-loader/lib/index.js?!./src/components/widgets/SlidoChat.vue?vue&type=script&lang=js&:10 Uncaught Error: Cannot find module 'lean-qr/extras/svg'
    at webpackMissingModule (cjs.js?!./node_modules/babel-loader/lib/index.js!./node_modules/cache-loader/dist/cjs.js?!./node_modules/vue-loader/lib/index.js?!./src/components/widgets/SlidoChat.vue?vue&type=script&lang=js&:10:45)
    at eval (cjs.js?!./node_modules/babel-loader/lib/index.js!./node_modules/cache-loader/dist/cjs.js?!./node_modules/vue-loader/lib/index.js?!./src/components/widgets/SlidoChat.vue?vue&type=script&lang=js&:10:138)
    at ./node_modules/cache-loader/dist/cjs.js?!./node_modules/babel-loader/lib/index.js!./node_modules/cache-loader/dist/cjs.js?!./node_modules/vue-loader/lib/index.js?!./src/components/widgets/SlidoChat.vue?vue&type=script&lang=js& (app.js:2090:1)
    at __webpack_require__ (app.js:849:30)
    at fn (app.js:151:20)
    at eval (SlidoChat.vue?df27:1:1)
    at ./src/components/widgets/SlidoChat.vue?vue&type=script&lang=js& (app.js:7017:1)
    at __webpack_require__ (app.js:849:30)
    at fn (app.js:151:20)
    at eval (SlidoChat.vue?bbb8:1:1)

Support ESM module format

When using lean-qr in my angular app it's warning me: depends on 'lean-qr'. CommonJS or AMD dependencies can cause optimization bailouts.

Would you consider adding an ESM build?

I don't know how much you know about the subject, but I can help you if needed :)

Do not rely on machine endianness for canvas render

Currently canvas rendering uses an optimisation where pixels are represented as Uint32, and colours are passed in as 0xAABBGGRR, but this only works on little endian machines. On a big endian machine, the channels would be reversed.

The function should take in colours as an array [red, green, blue, alpha] and convert this internally into a Uint32 value (since setting full pixels at a time is much faster). This conversion must not be through bit-shifting, but through an array buffer, since this will ensure the byte order is system native.

It may be necessary to support the current format as well for backwards compatibility.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.