Giter Club home page Giter Club logo

Comments (7)

monospaced avatar monospaced commented on August 24, 2024 1

Resurrecting this thread to comment that, thanks to @bgok (and also @arkarkark who essentially has the same idea) , fallback 'auto-minimum-version' functionality has now been added to master: 6f7abbe

I've also added a warning when the version is incremented: dac73ed

If at all possible, a sufficient version for the anticipated data should still be specified, to avoid unnecessarily triggering this brute force approach.

However, in the case where you simply don't know the amount of data that could be supplied (and also where you desire the lowest possible version to accommodate any data given) this does the job.

It doesn't tackle the error-correction-level, which still needs to be understood and handled manually.

Definitely room for improvement, but on balance I do prefer this approach to simply failing when the version is too low.

from angular-qrcode.

sequoiar avatar sequoiar commented on August 24, 2024

any update on it?

from angular-qrcode.

monospaced avatar monospaced commented on August 24, 2024

created a branch to work on this enhancement

https://github.com/monospaced/angular-qrcode/tree/calculate-version

from angular-qrcode.

arkarkark avatar arkarkark commented on August 24, 2024

I'd be really interested in this too. It'd be even nicer if you could also select the ECC level for the best results depending on the data size.

  1. first choose the lowest version that will hold your data
  2. then choose the best level that will still hold your data

from angular-qrcode.

arkarkark avatar arkarkark commented on August 24, 2024

This is so ugly I'm not even going to submit a pull request. but...
Here's one way that just brute forces the qr generator until it gets a valid qr code with no error

              version = 1;
              levelsArray = 'H Q M L'.split(' ');
              levelsIndex = 0

              while (true) {
                qr = qrcode(version, levelsArray[levelsIndex]);
                qr.addData(data);
                try {
                  qr.make();
                  error = false;
                  console.log('success', data.length, version, levelsArray[levelsIndex]);
                  break
                } catch(e) {
                  error = e.message;
                  levelsIndex++;
                  if (levelsIndex >= levelsArray.length) {
                    version++;
                    if (version > 10) {
                      return;
                    }
                    levelsIndex = 0;
                  }
                }
              }

from angular-qrcode.

arkarkark avatar arkarkark commented on August 24, 2024

alternatively this lookup table can be useful in your own code. I've found I need to lookup on the binary value for some reason.

  var qrLookup = [ // from https://developers.google.com/chart/infographics/docs/qr_codes
    {version: 1, level: 'H', digits: 17, chars: 10, binary: 7, kanji: 4},
    {version: 1, level: 'Q', digits: 27, chars: 16, binary: 11, kanji: 7},
    {version: 1, level: 'M', digits: 34, chars: 20, binary: 14, kanji: 8},
    {version: 1, level: 'L', digits: 41, chars: 25, binary: 17, kanji: 10},
    {version: 2, level: 'H', digits: 34, chars: 20, binary: 14, kanji: 8},
    {version: 2, level: 'Q', digits: 48, chars: 29, binary: 20, kanji: 12},
    {version: 2, level: 'M', digits: 63, chars: 38, binary: 26, kanji: 16},
    {version: 2, level: 'L', digits: 77, chars: 47, binary: 32, kanji: 20},
    {version: 3, level: 'H', digits: 58, chars: 35, binary: 24, kanji: 15},
    {version: 3, level: 'Q', digits: 77, chars: 47, binary: 32, kanji: 20},
    {version: 3, level: 'M', digits: 101, chars: 61, binary: 42, kanji: 26},
    {version: 3, level: 'L', digits: 127, chars: 77, binary: 53, kanji: 32},
    {version: 4, level: 'H', digits: 82, chars: 50, binary: 34, kanji: 21},
    {version: 4, level: 'Q', digits: 111, chars: 67, binary: 46, kanji: 28},
    {version: 4, level: 'M', digits: 149, chars: 90, binary: 62, kanji: 38},
    {version: 4, level: 'L', digits: 187, chars: 114, binary: 78, kanji: 48}
  ];
_.find(qrLookup, (q) -> q.binary  > data.length)

is useful.

from angular-qrcode.

monospaced avatar monospaced commented on August 24, 2024

Hi @arkarkark thanks for the contribution, that is super useful 👍

Unfortunately I'm up to my ears in client work at the moment, so don't have a lot of time for open source right now :(

Hopefully in about a month or so I will get back into this, and look at implement the lookup solution :)

from angular-qrcode.

Related Issues (20)

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.