Skip to content

Commit b65f5eb

Browse files
committed
New version 3.5.0 release!
+ You can control the QR Code version(0-40) now, 0 is automatically choose the closest version based on the text length. (If you set a value less than the minimum version available for text, the minimum version is automatically used.)
1 parent a9c47f9 commit b65f5eb

File tree

6 files changed

+44
-10
lines changed

6 files changed

+44
-10
lines changed

demo/demo_node.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ qrcode.toDataURL().then(data=>{
190190
// ================================ JPG Test
191191

192192
var config5 = Object.assign({}, config, {
193-
format:'JPG'
193+
format:'JPG',
194+
version: 6
194195
});
195196
var config6 = Object.assign({}, config2, {
196197
format:'JPG'

demo/q.jpg

20.3 KB
Loading

index.js

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* NodeJS QRCode generator. Save image to file. Support Dot style, Logo, Background image, Colorful, Title, etc.(Running without DOM on server side)
55
*
6-
* Version 3.4.0
6+
* Version 3.5.0
77
*
88
* @author [ inthinkcolor@gmail.com ]
99
*
@@ -989,7 +989,11 @@ var QRCodeLimitLength = [
989989
* @param {Number} nCorrectLevel
990990
* @return {Number} type
991991
*/
992-
function _getTypeNumber(sText, nCorrectLevel) {
992+
function _getTypeNumber(sText, _htOption) {
993+
994+
var nCorrectLevel = _htOption.correctLevel;
995+
996+
993997
var nType = 1;
994998
var length = _getUTF8Length(sText);
995999

@@ -1017,11 +1021,21 @@ function _getTypeNumber(sText, nCorrectLevel) {
10171021
nType++;
10181022
}
10191023
}
1020-
10211024
if (nType > QRCodeLimitLength.length) {
10221025
throw new Error("Too long data");
10231026
}
10241027

1028+
if(_htOption.version!=0){
1029+
if(nType<=_htOption.version){
1030+
nType=_htOption.version;
1031+
_htOption.runVersion = nType;
1032+
}else{
1033+
console.warn("QR Code version "+_htOption.version+" too small, run version use "+nType);
1034+
_htOption.runVersion = nType;
1035+
}
1036+
}
1037+
1038+
10251039
return nType;
10261040
}
10271041

@@ -1455,7 +1469,11 @@ function QRCode(vOption) {
14551469
// ==== Images format
14561470
format: 'PNG', // 'PNG', 'JPG'
14571471
compressionLevel: 6, // ZLIB compression level (0-9). default is 6
1458-
quality: 0.75 // An object specifying the quality (0 to 1). default is 0.75. (JPGs only)
1472+
quality: 0.75, // An object specifying the quality (0 to 1). default is 0.75. (JPGs only)
1473+
1474+
// ==== Versions
1475+
version: 0 // The symbol versions of QR Code range from Version 1 to Version 40. default 0 means automatically choose the closest version based on the text length.
1476+
14591477
};
14601478
if (typeof vOption === 'string') {
14611479
vOption = {
@@ -1470,6 +1488,11 @@ function QRCode(vOption) {
14701488
}
14711489
}
14721490

1491+
if(this._htOption.version<0 || this._htOption.version>40){
1492+
console.warn("QR Code version '"+this._htOption.version+"' is invalidate, reset to 0")
1493+
this._htOption.version=0;
1494+
}
1495+
14731496
this._htOption.format=this._htOption.format.toUpperCase();
14741497
if(this._htOption.format!='PNG' && this._htOption.format!='JPG'){
14751498
console.warn("Image format '"+this._htOption.format+"' is invalidate, reset to 'PNG'")
@@ -1500,7 +1523,7 @@ function QRCode(vOption) {
15001523
this._htOption.height = this._htOption.height + this._htOption.titleHeight;
15011524

15021525
this._oQRCode = null;
1503-
this._oQRCode = new QRCodeModel(_getTypeNumber(this._htOption.text, this._htOption.correctLevel), this._htOption.correctLevel);
1526+
this._oQRCode = new QRCodeModel(_getTypeNumber(this._htOption.text, this._htOption), this._htOption.correctLevel);
15041527
this._oQRCode.addData(this._htOption.text);
15051528
this._oQRCode.make();
15061529
}

index.min.js

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "easyqrcodejs-nodejs",
3-
"version": "3.4.0",
3+
"version": "3.5.0",
44
"description": "NodeJS QRCode generator. Support Dot style, Logo, Background image, Colorful, Title, etc.",
55
"main": "index.min.js",
66
"scripts": {},

readme.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,14 @@ var qrcode = new QRCode(options);
202202
/*
203203
format: 'PNG', // 'PNG', 'JPG'
204204
compressionLevel: 6, // ZLIB compression level (0-9). default is 6
205-
quality: 0.75 // An object specifying the quality (0 to 1). default is 0.75. (JPGs only)
205+
quality: 0.75, // An object specifying the quality (0 to 1). default is 0.75. (JPGs only)
206206
*/
207+
208+
// ==== Versions
209+
/*
210+
version: 0 // The symbol versions of QR Code range from Version 1 to Version 40. default 0 means automatically choose the closest version based on the text length.
211+
212+
*/
207213
}
208214
```
209215

@@ -264,7 +270,10 @@ var qrcode = new QRCode(options);
264270
| **format** | N | String | `PNG` | 'PNG' or 'JPG' |
265271
| **compressionLevel** | N | Number | `6` | ZLIB compression level between 0 and 9. (**PNGs only**) |
266272
| **quality** | N | Number | `0.75` | An object specifying the quality (0 to 1). (**JPGs only**) |
273+
| Version options| --- | ---|---|---|
274+
| **version** | N | Number | `0` | The symbol versions of QR Code range from Version `1` to Version `40`. default 0 means automatically choose the closest version based on the text length. [Information capacity and versions of QR Codes](https://www.qrcode.com/en/about/version.html) **NOTE**: If you set a value less than the minimum version available for text, the minimum version is automatically used. |
267275

276+
268277
### Methods
269278

270279
- **saveImage(ImagesFormatOptions)**

0 commit comments

Comments
 (0)