Skip to content

Commit a9c47f9

Browse files
committed
NodeJS server side QRCode image generator.
New version 3.4.0 release! + Add Images format options, support generator JPG image ``` // ==== Images format format: 'PNG', // 'PNG', 'JPG' compressionLevel: 6, // ZLIB compression level (0-9). default is 6 quality: 0.75 // An object specifying the quality (0 to 1). default is 0.75. (JPGs only) ``` # Fixed a bug when quietZone and title were used together # Change onRenderingStart() to onRenderingStart(qrCodeOptions)
1 parent 02fab46 commit a9c47f9

File tree

10 files changed

+257
-154
lines changed

10 files changed

+257
-154
lines changed

demo/demo_node.js

Lines changed: 74 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
const QRCode = require('../index.min');
22

33

4-
var qrcode = new QRCode({
4+
5+
// ================================ PNG Configs
6+
7+
8+
var config={
59
// ====== Basic
610
text: "www.easyproject.cn/donation",
711
width: 256,
@@ -11,11 +15,9 @@ var qrcode = new QRCode({
1115
colorLight: "#ffffff",
1216
correctLevel: QRCode.CorrectLevel.H, // L, M, Q, H
1317
dotScale: 1 // Must be greater than 0, less than or equal to 1. default is 1
14-
});
18+
}
1519

16-
17-
18-
var qrcode2 = new QRCode({
20+
var config2={
1921
// ====== Basic
2022
text: "www.easyproject.cn/donation",
2123

@@ -26,7 +28,7 @@ var qrcode2 = new QRCode({
2628
dotScale: 0.5 ,// Must be greater than 0, less than or equal to 1. default is 1
2729
colorDark: "#473C8B",
2830
colorLight: "#FFFACD",
29-
31+
3032
// === Posotion Pattern(Eye) Color
3133
PI: '#BF3030',
3234
PO: '#269926',
@@ -48,28 +50,28 @@ var qrcode2 = new QRCode({
4850
// === Background image
4951
backgroundImage: 'logo.png',
5052
backgroundImageAlpha: 0.3,
51-
autoColor: true,
52-
53-
});
54-
53+
autoColor: true
54+
}
5555

56-
var qrcode3 = new QRCode({
56+
var config3={
5757
// ====== Basic
5858
text: "www.easyproject.cn/donation",
5959

6060
width: 400,
6161
height: 400,
62-
quietZone: 20,
6362
correctLevel: QRCode.CorrectLevel.H, // L, M, Q, H
6463
dotScale: 0.5 ,// Must be greater than 0, less than or equal to 1. default is 1
6564
colorDark: "#473C8B",
6665
colorLight: "#FFFACD",
67-
66+
67+
// QuietZone
68+
quietZone:15,
69+
6870
// === Title
6971
title: 'EasyQRCode', // Title
7072
titleFont: "bold 24px Arial", // Title font
7173
titleColor: "#004284", // Title Color
72-
titleBackgroundColor: "#fffff", // Title Background
74+
titleBackgroundColor: "#ffffff", // Title Background
7375
titleHeight: 70, // Title height, include subTitle
7476
titleTop: 25, // Title draw position(Y coordinate), default is 30
7577

@@ -105,33 +107,31 @@ var qrcode3 = new QRCode({
105107
// logoHeight:80,
106108
logoBackgroundColor: '#FFF8DC', // Logo backgroud color, Invalid when `logBgTransparent` is true; default is '#ffffff'
107109
logoBackgroundTransparent: false, // Whether use transparent image, default is false
108-
110+
109111
// === Background image
110112
backgroundImage: 'logo.png',
111113
backgroundImageAlpha: 0.3,
112114
autoColor: true,
113115

114-
onRenderingStart:function(){
115-
console.info("The QRCode file `q3.png` was created.");
116+
onRenderingStart:function(options){
117+
console.info("The QRCode file `q3."+options.format+"` was created.");
116118
}
117-
118-
});
119+
}
119120

120-
var qrcode4 = new QRCode({
121+
var config4={
121122
// ====== Basic
122123
text: "www.easyproject.cn/donation",
123124

124125
width: 400,
125126
height: 400,
126-
quietZone: 20,
127127
correctLevel: QRCode.CorrectLevel.H, // L, M, Q, H
128128
dotScale: 0.5 ,// Must be greater than 0, less than or equal to 1. default is 1
129129
colorDark: "#473C8B",
130130
colorLight: "#FFFACD",
131-
132-
// QuietZone
133-
quietZone:15,
134-
quietZoneColor:'#00CED1',
131+
132+
// QuietZone
133+
quietZone:15,
134+
quietZoneColor:'#00CED1',
135135

136136
// === Posotion Pattern(Eye) Color
137137
PI: '#BF3030',
@@ -159,32 +159,70 @@ var qrcode4 = new QRCode({
159159
// logoHeight:80,
160160
logoBackgroundColor: '#FFF8DC', // Logo backgroud color, Invalid when `logBgTransparent` is true; default is '#ffffff'
161161
logoBackgroundTransparent: false // Whether use transparent image, default is false
162-
163-
});
162+
}
164163

165-
qrcode.saveImage({
166-
path: 'q.png',
167-
compressionLevel: 6
168-
});
169164

165+
// ================================ PNG Test
166+
167+
var qrcode = new QRCode(config);
168+
var qrcode2 = new QRCode(config2);
169+
var qrcode3 = new QRCode(config3);
170+
var qrcode4 = new QRCode(config4);
170171

172+
qrcode.saveImage({
173+
path: 'q.png'
174+
});
171175
qrcode2.saveImage({
172176
path: 'q2.png'
173177
});
174-
175-
176178
qrcode3.saveImage({
177179
path: 'q3.png'
178180
});
179-
180181
qrcode4.saveImage({
181182
path: 'q4.png'
182183
});
183-
184-
185184
qrcode.toDataURL().then(data=>{
186185
console.info('======QRCode PNG DataURL======')
187186
console.info(data)
188187
console.info('')
189188
});
190189

190+
// ================================ JPG Test
191+
192+
var config5 = Object.assign({}, config, {
193+
format:'JPG'
194+
});
195+
var config6 = Object.assign({}, config2, {
196+
format:'JPG'
197+
});
198+
var config7 = Object.assign({}, config3, {
199+
format:'JPG'
200+
});
201+
var config8 = Object.assign({}, config4, {
202+
format:'JPG'
203+
});
204+
205+
var qrcode5 = new QRCode(config5);
206+
var qrcode6 = new QRCode(config6);
207+
var qrcode7 = new QRCode(config7);
208+
var qrcode8 = new QRCode(config8);
209+
210+
211+
qrcode5.saveImage({
212+
path: 'q.jpg'
213+
});
214+
qrcode6.saveImage({
215+
path: 'q2.jpg'
216+
});
217+
qrcode7.saveImage({
218+
path: 'q3.jpg'
219+
});
220+
qrcode8.saveImage({
221+
path: 'q4.jpg'
222+
});
223+
224+
qrcode5.toDataURL().then(data=>{
225+
console.info('======QRCode JPG DataURL======')
226+
console.info(data)
227+
console.info('')
228+
});

demo/q.jpg

2.67 KB
Loading

demo/q2.jpg

48 KB
Loading

demo/q3.jpg

47.8 KB
Loading

demo/q3.png

-2.19 KB
Loading

demo/q4.jpg

44.8 KB
Loading

0 commit comments

Comments
 (0)