Comments (7)
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.
any update on it?
from angular-qrcode.
created a branch to work on this enhancement
https://github.com/monospaced/angular-qrcode/tree/calculate-version
from angular-qrcode.
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.
- first choose the lowest version that will hold your data
- then choose the best level that will still hold your data
from angular-qrcode.
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.
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.
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)
- Copy QRCode with CTRL+C HOT 2
- not displaying QR code HOT 3
- "qrcode" global naming has conflict with another library which scans qrcode HOT 1
- qrcode is not defined HOT 5
- qrcode will not be generated when 'data' string is too long
- Not see nothing HOT 2
- Wrong qrcode-generator version in bower.json HOT 5
- Download qr code with unique name HOT 1
- url too long HOT 1
- Download is not working on MS Edge HOT 1
- How to print on a device HOT 1
- angularjs bower HOT 2
- Printing issues HOT 2
- qrcode is not defined HOT 2
- Error not working HOT 1
- not an angular project HOT 1
- simply its an html code HOT 1
- Demo not working HOT 2
- bower-qrcode-generator has invalid git url, sometimes it does not work. HOT 2
- How to set size of QR code with higher version number (module)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angular-qrcode.