qrbit 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +421 -0
- package/dist/native.d.ts +40 -0
- package/dist/native.js +566 -0
- package/dist/qrbit.cjs +394 -0
- package/dist/qrbit.cjs.map +1 -0
- package/dist/qrbit.d.cts +237 -0
- package/dist/qrbit.d.ts +237 -0
- package/dist/qrbit.darwin-arm64.node +0 -0
- package/dist/qrbit.darwin-x64.node +0 -0
- package/dist/qrbit.js +365 -0
- package/dist/qrbit.js.map +1 -0
- package/dist/qrbit.linux-x64-gnu.node +0 -0
- package/dist/qrbit.linux-x64-musl.node +0 -0
- package/dist/qrbit.win32-x64-msvc.node +0 -0
- package/package.json +96 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Jared Wray
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
<div align="center"><img src="./site/logo.svg" alt="QrBit Logo" /></div>
|
|
2
|
+
|
|
3
|
+
# Qrbit
|
|
4
|
+
|
|
5
|
+
[](https://codecov.io/gh/jaredwray/qrbit)
|
|
6
|
+
[](https://github.com/jaredwray/qrbit/actions/workflows/tests.yml)
|
|
7
|
+
[](https://www.npmjs.com/package/qrbit)
|
|
8
|
+
[](https://www.npmjs.com/package/qrbit)
|
|
9
|
+
[](https://github.com/jaredwray/qrbit/blob/main/LICENSE)
|
|
10
|
+
|
|
11
|
+
A fast QR code generator with logo embedding support, built with Rust and native node packages for best performance while avoiding additional modules (example: canvas).
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
- **Fast**: Built with Rust (for logos) for maximum performance and caching 🚀
|
|
16
|
+
- **Fast SVG**: High performance SVG support via `QrCode` when no logo is needed
|
|
17
|
+
- **Cross-platform**: Works on iOS, Windows, Linux, and macOS
|
|
18
|
+
- **Logo embedding**: Add custom logos to your QR codes with no need for node canvas!
|
|
19
|
+
- **Customizable**: Custom colors, sizes, and margins
|
|
20
|
+
- **Multiple formats**: Generate SVG and PNG outputs
|
|
21
|
+
- **Scalable**: With caching you can also use a secondary store for persistence
|
|
22
|
+
- **Well-tested**: Comprehensive test coverage with Vitest
|
|
23
|
+
- **Maintained**: Actively maintained with regular updates
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm install qrbit
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
# Requirements
|
|
32
|
+
|
|
33
|
+
- Node.js >= 18
|
|
34
|
+
- Supported platforms: Windows, macOS, Linux (x86, x64, ARM64)
|
|
35
|
+
|
|
36
|
+
# Usage
|
|
37
|
+
|
|
38
|
+
```javascript
|
|
39
|
+
const qr = new QrBit({ text: "https://github.com/jaredwray/qrbit", size: 200 });
|
|
40
|
+
const svg = await qr.toSvg();
|
|
41
|
+
console.log(svg); // here is the svg!
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Here is how you add a logo:
|
|
45
|
+
|
|
46
|
+
```javascript
|
|
47
|
+
const qr = new QrBit({
|
|
48
|
+
text: "https://github.com/jaredwray/qrbit",
|
|
49
|
+
logo: '/path/to/logo.png',
|
|
50
|
+
size: 200 });
|
|
51
|
+
const svg = await qr.toSvg();
|
|
52
|
+
console.log(svg); // here is the svg with an embedded logo!
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
# API
|
|
56
|
+
|
|
57
|
+
## constructor(options: QrOptions)
|
|
58
|
+
|
|
59
|
+
Creates a new QrBit instance with the specified options.
|
|
60
|
+
|
|
61
|
+
**Parameters:**
|
|
62
|
+
- `options` (QrOptions): Configuration object for the QR code
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
interface QrOptions {
|
|
66
|
+
text: string; // The text content to encode
|
|
67
|
+
size?: number; // Size in pixels (default: 200)
|
|
68
|
+
margin?: number; // Margin in pixels (default: undefined)
|
|
69
|
+
logo?: string | Buffer; // Logo file path or buffer
|
|
70
|
+
logoSizeRatio?: number; // Logo size ratio (default: 0.2)
|
|
71
|
+
backgroundColor?: string; // Background color (default: "#FFFFFF")
|
|
72
|
+
foregroundColor?: string; // Foreground color (default: "#000000")
|
|
73
|
+
cache?: Cacheable | boolean; // Caching configuration (default: true)
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
**Example:**
|
|
78
|
+
```javascript
|
|
79
|
+
import { QrBit } from 'qrbit';
|
|
80
|
+
|
|
81
|
+
const qr = new QrBit({
|
|
82
|
+
text: "https://github.com/jaredwray/qrbit",
|
|
83
|
+
size: 300,
|
|
84
|
+
margin: 20,
|
|
85
|
+
logo: "./logo.png",
|
|
86
|
+
logoSizeRatio: 0.25,
|
|
87
|
+
backgroundColor: "#FFFFFF",
|
|
88
|
+
foregroundColor: "#000000"
|
|
89
|
+
});
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Properties
|
|
93
|
+
|
|
94
|
+
### text
|
|
95
|
+
Get or set the text content for the QR code.
|
|
96
|
+
|
|
97
|
+
```javascript
|
|
98
|
+
const qr = new QrBit({ text: "Hello World" });
|
|
99
|
+
console.log(qr.text); // "Hello World"
|
|
100
|
+
qr.text = "New content";
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### size
|
|
104
|
+
Get or set the size of the QR code in pixels.
|
|
105
|
+
|
|
106
|
+
```javascript
|
|
107
|
+
const qr = new QrBit({ text: "Hello World" });
|
|
108
|
+
console.log(qr.size); // 200 (default)
|
|
109
|
+
qr.size = 400;
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### margin
|
|
113
|
+
Get or set the margin around the QR code in pixels.
|
|
114
|
+
|
|
115
|
+
```javascript
|
|
116
|
+
const qr = new QrBit({ text: "Hello World" });
|
|
117
|
+
console.log(qr.margin); // undefined (default)
|
|
118
|
+
qr.margin = 20;
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### logo
|
|
122
|
+
Get or set the logo as a file path or buffer.
|
|
123
|
+
|
|
124
|
+
```javascript
|
|
125
|
+
const qr = new QrBit({ text: "Hello World" });
|
|
126
|
+
qr.logo = "./path/to/logo.png";
|
|
127
|
+
// or
|
|
128
|
+
qr.logo = fs.readFileSync("./logo.png");
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### logoSizeRatio
|
|
132
|
+
Get or set the logo size ratio relative to QR code size (0.0 to 1.0).
|
|
133
|
+
|
|
134
|
+
```javascript
|
|
135
|
+
const qr = new QrBit({ text: "Hello World" });
|
|
136
|
+
qr.logoSizeRatio = 0.3; // 30% of QR code size
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### backgroundColor
|
|
140
|
+
Get or set the background color in hex format.
|
|
141
|
+
|
|
142
|
+
```javascript
|
|
143
|
+
const qr = new QrBit({ text: "Hello World" });
|
|
144
|
+
qr.backgroundColor = "#FF0000"; // Red background
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### foregroundColor
|
|
148
|
+
Get or set the foreground color in hex format.
|
|
149
|
+
|
|
150
|
+
```javascript
|
|
151
|
+
const qr = new QrBit({ text: "Hello World" });
|
|
152
|
+
qr.foregroundColor = "#FFFFFF"; // White foreground
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### cache
|
|
156
|
+
Get or set the cache instance for performance optimization.
|
|
157
|
+
|
|
158
|
+
```javascript
|
|
159
|
+
import { Cacheable } from 'cacheable';
|
|
160
|
+
|
|
161
|
+
const qr = new QrBit({ text: "Hello World" });
|
|
162
|
+
qr.cache = new Cacheable(); // Custom cache instance
|
|
163
|
+
qr.cache = false; // Disable caching
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## Methods
|
|
167
|
+
|
|
168
|
+
### .toSvg(options?: toOptions): Promise<string>
|
|
169
|
+
|
|
170
|
+
Generate SVG QR code with optional caching. Uses native QRCode library for simple cases, Rust implementation for logos.
|
|
171
|
+
|
|
172
|
+
**Parameters:**
|
|
173
|
+
- `options.cache?: boolean` - Whether to use caching (default: true)
|
|
174
|
+
|
|
175
|
+
**Returns:** Promise<string> - The SVG string
|
|
176
|
+
|
|
177
|
+
```javascript
|
|
178
|
+
const qr = new QrBit({ text: "Hello World" });
|
|
179
|
+
const svg = await qr.toSvg();
|
|
180
|
+
console.log(svg); // <svg xmlns="http://www.w3.org/2000/svg"...
|
|
181
|
+
|
|
182
|
+
// Without caching
|
|
183
|
+
const svgNoCache = await qr.toSvg({ cache: false });
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### .toSvgFile(filePath: string, options?: toOptions): Promise<void>
|
|
187
|
+
|
|
188
|
+
Generate SVG QR code and save it to a file. Creates directories if they don't exist.
|
|
189
|
+
|
|
190
|
+
**Parameters:**
|
|
191
|
+
- `filePath: string` - The file path where to save the SVG
|
|
192
|
+
- `options.cache?: boolean` - Whether to use caching (default: true)
|
|
193
|
+
|
|
194
|
+
**Returns:** Promise<void>
|
|
195
|
+
|
|
196
|
+
```javascript
|
|
197
|
+
const qr = new QrBit({ text: "Hello World" });
|
|
198
|
+
await qr.toSvgFile("./output/qr-code.svg");
|
|
199
|
+
|
|
200
|
+
// With options
|
|
201
|
+
await qr.toSvgFile("./output/qr-code.svg", { cache: false });
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### .toPng(options?: toOptions): Promise<Buffer>
|
|
205
|
+
|
|
206
|
+
Generate PNG QR code with optional caching. Uses high-performance SVG to PNG conversion.
|
|
207
|
+
|
|
208
|
+
**Parameters:**
|
|
209
|
+
- `options.cache?: boolean` - Whether to use caching (default: true)
|
|
210
|
+
|
|
211
|
+
**Returns:** Promise<Buffer> - The PNG buffer
|
|
212
|
+
|
|
213
|
+
```javascript
|
|
214
|
+
const qr = new QrBit({ text: "Hello World" });
|
|
215
|
+
const pngBuffer = await qr.toPng();
|
|
216
|
+
|
|
217
|
+
// Save to file
|
|
218
|
+
fs.writeFileSync("qr-code.png", pngBuffer);
|
|
219
|
+
|
|
220
|
+
// Without caching
|
|
221
|
+
const pngNoCache = await qr.toPng({ cache: false });
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
### .toPngFile(filePath: string, options?: toOptions): Promise<void>
|
|
225
|
+
|
|
226
|
+
Generate PNG QR code and save it to a file. Creates directories if they don't exist.
|
|
227
|
+
|
|
228
|
+
**Parameters:**
|
|
229
|
+
- `filePath: string` - The file path where to save the PNG
|
|
230
|
+
- `options.cache?: boolean` - Whether to use caching (default: true)
|
|
231
|
+
|
|
232
|
+
**Returns:** Promise<void>
|
|
233
|
+
|
|
234
|
+
```javascript
|
|
235
|
+
const qr = new QrBit({ text: "Hello World" });
|
|
236
|
+
await qr.toPngFile("./output/qr-code.png");
|
|
237
|
+
|
|
238
|
+
// With options
|
|
239
|
+
await qr.toPngFile("./output/qr-code.png", { cache: false });
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
# Benchmarks
|
|
243
|
+
|
|
244
|
+
## QR Codes SVG (No Logo)
|
|
245
|
+
| name | summary | ops/sec | time/op | margin | samples |
|
|
246
|
+
|-----------------------------------------|:---------:|----------:|----------:|:--------:|----------:|
|
|
247
|
+
| QRCode toString (v1.5.4) | 🥇 | 5K | 211µs | ±0.46% | 5K |
|
|
248
|
+
| QrBit toSvg (Native) (v0.1.0) | -4.5% | 5K | 226µs | ±0.91% | 4K |
|
|
249
|
+
| QrBit toSvg (Rust) (v0.1.0) | -84% | 774 | 1ms | ±1.32% | 745 |
|
|
250
|
+
| styled-qr-code-node toBuffer (v1.5.2) | -90% | 470 | 2ms | ±1.32% | 464 |
|
|
251
|
+
|
|
252
|
+
`Rust` is there for performance and when doing heavy image processing without needing node `canvas` installed. If you do not add a logo then the `Native` version is what you will get for SVG.
|
|
253
|
+
|
|
254
|
+
## QR Codes PNG (No Logo)
|
|
255
|
+
| name | summary | ops/sec | time/op | margin | samples |
|
|
256
|
+
|-----------------------------------------|:---------:|----------:|----------:|:--------:|----------:|
|
|
257
|
+
| QrBit toPng (v0.1.0) | 🥇 | 1K | 681µs | ±0.63% | 1K |
|
|
258
|
+
| QRCode toBuffer (v1.5.4) | -64% | 539 | 2ms | ±1.48% | 528 |
|
|
259
|
+
| styled-qr-code-node toBuffer (v1.5.2) | -89% | 169 | 6ms | ±1.16% | 169 |
|
|
260
|
+
|
|
261
|
+
`Rust` is used for `toPng()` to optimize performance for PNG generation and heavy image processing without needing node `canvas` installed.
|
|
262
|
+
|
|
263
|
+
## QR Codes with Embedded Logos
|
|
264
|
+
| name | summary | ops/sec | time/op | margin | samples |
|
|
265
|
+
|------------------------------------|:---------:|----------:|----------:|:--------:|----------:|
|
|
266
|
+
| QrBit PNG (Path) (v0.1.0) | 🥇 | 926 | 1ms | ±0.47% | 923 |
|
|
267
|
+
| QrBit SVG (Path) (v0.1.0) | -32% | 628 | 2ms | ±1.21% | 613 |
|
|
268
|
+
| QrBit PNG (Buffer) (v0.1.0) | -82% | 169 | 6ms | ±0.72% | 170 |
|
|
269
|
+
| QrBit SVG (Buffer) (v0.1.0) | -83% | 155 | 6ms | ±0.86% | 155 |
|
|
270
|
+
| styled-qr-code-node PNG (v1.5.2) | -88% | 116 | 9ms | ±0.69% | 116 |
|
|
271
|
+
| styled-qr-code-node SVG (v1.5.2) | -89% | 103 | 10ms | ±0.73% | 103 |
|
|
272
|
+
|
|
273
|
+
`Buffer` is much slower as we have to push the stream across to the rust module. For fastest performance provide the path of the image.
|
|
274
|
+
|
|
275
|
+
## QR Codes SVG with Caching
|
|
276
|
+
| name | summary | ops/sec | time/op | margin | samples |
|
|
277
|
+
|-----------------------------------------|:---------:|----------:|----------:|:--------:|----------:|
|
|
278
|
+
| QrBit toSvg (Native) (v0.1.0) | 🥇 | 52K | 148µs | ±1.96% | 7K |
|
|
279
|
+
| QRCode toString (v1.5.4) | -90% | 5K | 206µs | ±0.45% | 5K |
|
|
280
|
+
| QrBit toSvg (Rust) (v0.1.0) | -99% | 772 | 1ms | ±1.26% | 746 |
|
|
281
|
+
| styled-qr-code-node toBuffer (v1.5.2) | -99% | 471 | 2ms | ±1.44% | 464 |
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
## QR Codes PNG with Caching
|
|
285
|
+
| name | summary | ops/sec | time/op | margin | samples |
|
|
286
|
+
|-----------------------------------------|:---------:|----------:|----------:|:--------:|----------:|
|
|
287
|
+
| QrBit toPng (v0.1.0) | 🥇 | 13K | 605µs | ±1.81% | 2K |
|
|
288
|
+
| QRCode toBuffer (v1.5.4) | -96% | 535 | 2ms | ±1.61% | 523 |
|
|
289
|
+
| styled-qr-code-node toBuffer (v1.5.2) | -99% | 165 | 6ms | ±0.95% | 165 |
|
|
290
|
+
|
|
291
|
+
# Examples
|
|
292
|
+
|
|
293
|
+
The `examples/` directory contains various QR code examples showcasing different features and use cases. You can generate these examples by running:
|
|
294
|
+
|
|
295
|
+
```bash
|
|
296
|
+
pnpm generate-examples
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
## 1. Basic QR Code
|
|
300
|
+
Simple QR code with default settings.
|
|
301
|
+
```javascript
|
|
302
|
+
const qr = new QrBit({ text: "Hello World!" });
|
|
303
|
+
await qr.toPngFile("01_basic.png");
|
|
304
|
+
```
|
|
305
|
+

|
|
306
|
+
|
|
307
|
+
## 2. URL QR Code
|
|
308
|
+
QR code encoding a GitHub URL.
|
|
309
|
+
```javascript
|
|
310
|
+
const qr = new QrBit({ text: "https://github.com/jaredwray/qrbit", size: 200 });
|
|
311
|
+
await qr.toSvgFile("02_url.svg");
|
|
312
|
+
```
|
|
313
|
+

|
|
314
|
+
|
|
315
|
+
## 3. Large Size QR Code
|
|
316
|
+
QR code with increased size for better scanning.
|
|
317
|
+
```javascript
|
|
318
|
+
const qr = new QrBit({ text: "Large QR", size: 400 });
|
|
319
|
+
await qr.toPngFile("03_large_size.png");
|
|
320
|
+
```
|
|
321
|
+

|
|
322
|
+
|
|
323
|
+
## 4. Inverted Colors
|
|
324
|
+
Black background with white foreground.
|
|
325
|
+
```javascript
|
|
326
|
+
const qr = new QrBit({
|
|
327
|
+
text: "Inverted Colors",
|
|
328
|
+
backgroundColor: "#000000",
|
|
329
|
+
foregroundColor: "#FFFFFF"
|
|
330
|
+
});
|
|
331
|
+
await qr.toSvgFile("04_inverted.svg");
|
|
332
|
+
```
|
|
333
|
+

|
|
334
|
+
|
|
335
|
+
## 5. Red Theme
|
|
336
|
+
Custom red background theme.
|
|
337
|
+
```javascript
|
|
338
|
+
const qr = new QrBit({
|
|
339
|
+
text: "Red Theme",
|
|
340
|
+
backgroundColor: "#FF0000",
|
|
341
|
+
foregroundColor: "#FFFFFF"
|
|
342
|
+
});
|
|
343
|
+
await qr.toPngFile("05_red_theme.png");
|
|
344
|
+
```
|
|
345
|
+

|
|
346
|
+
|
|
347
|
+
## 6. Small Logo
|
|
348
|
+
QR code with a small embedded logo.
|
|
349
|
+
```javascript
|
|
350
|
+
const qr = new QrBit({
|
|
351
|
+
text: "logo small",
|
|
352
|
+
logo: "./logo.png",
|
|
353
|
+
logoSizeRatio: 0.2
|
|
354
|
+
});
|
|
355
|
+
await qr.toPngFile("06_logo_small.png");
|
|
356
|
+
```
|
|
357
|
+

|
|
358
|
+
|
|
359
|
+
## 7. Large Logo with Custom Colors
|
|
360
|
+
Large logo with red background theme.
|
|
361
|
+
```javascript
|
|
362
|
+
const qr = new QrBit({
|
|
363
|
+
text: "logo large red",
|
|
364
|
+
logo: "./logo.png",
|
|
365
|
+
size: 400,
|
|
366
|
+
logoSizeRatio: 0.3,
|
|
367
|
+
backgroundColor: "#FF0000",
|
|
368
|
+
foregroundColor: "#FFFFFF"
|
|
369
|
+
});
|
|
370
|
+
await qr.toSvgFile("07_logo_large_red.svg");
|
|
371
|
+
```
|
|
372
|
+

|
|
373
|
+
|
|
374
|
+
## 8. WiFi QR Code
|
|
375
|
+
QR code for WiFi network connection.
|
|
376
|
+
```javascript
|
|
377
|
+
const qr = new QrBit({
|
|
378
|
+
text: "WIFI:T:WPA;S:MyNetwork;P:MyPassword;;"
|
|
379
|
+
});
|
|
380
|
+
await qr.toPngFile("08_wifi.png");
|
|
381
|
+
```
|
|
382
|
+

|
|
383
|
+
|
|
384
|
+
## 9. Large Margin with Blue Theme
|
|
385
|
+
Custom margin and blue color scheme.
|
|
386
|
+
```javascript
|
|
387
|
+
const qr = new QrBit({
|
|
388
|
+
text: "https://github.com/jaredwray/qrbit",
|
|
389
|
+
size: 300,
|
|
390
|
+
margin: 40,
|
|
391
|
+
backgroundColor: "#0000FF",
|
|
392
|
+
foregroundColor: "#FFFFFF"
|
|
393
|
+
});
|
|
394
|
+
await qr.toSvgFile("09_large_margin_blue.svg");
|
|
395
|
+
```
|
|
396
|
+

|
|
397
|
+
|
|
398
|
+
## 10. Buffer Logo
|
|
399
|
+
Using a logo loaded from a Buffer instead of file path.
|
|
400
|
+
```javascript
|
|
401
|
+
const logoBuffer = fs.readFileSync("./logo.png");
|
|
402
|
+
const qr = new QrBit({
|
|
403
|
+
text: "Buffer Logo",
|
|
404
|
+
logo: logoBuffer,
|
|
405
|
+
logoSizeRatio: 0.2,
|
|
406
|
+
backgroundColor: "#F0F0F0",
|
|
407
|
+
foregroundColor: "#333333"
|
|
408
|
+
});
|
|
409
|
+
await qr.toPngFile("10_buffer_logo.png");
|
|
410
|
+
```
|
|
411
|
+

|
|
412
|
+
|
|
413
|
+
These examples demonstrate the versatility and capabilities of QrBit for generating QR codes with various customizations, from simple text encoding to complex styled codes with embedded logos.
|
|
414
|
+
|
|
415
|
+
## Contributing
|
|
416
|
+
|
|
417
|
+
Please read our [Contributing Guidelines](./CONTRIBUTING.md) and also our [Code of Conduct](./CODE_OF_CONDUCT.md).
|
|
418
|
+
|
|
419
|
+
## License and Copyright
|
|
420
|
+
|
|
421
|
+
[MIT & Copyright (c) Jared Wray](https://github.com/jaredwray/qrbit/blob/main/LICENSE)
|
package/dist/native.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/* auto-generated by NAPI-RS */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export declare function convertSvgToPng(svgContent: string, width?: number | undefined | null, height?: number | undefined | null): Buffer
|
|
4
|
+
|
|
5
|
+
export declare function generateQr(options: QrOptions): QrResult
|
|
6
|
+
|
|
7
|
+
export declare function generateQrPng(options: QrOptions): Buffer
|
|
8
|
+
|
|
9
|
+
export declare function generateQrPngWithBuffer(options: QrOptionsWithBuffer): Buffer
|
|
10
|
+
|
|
11
|
+
export declare function generateQrSvg(options: QrOptions): string
|
|
12
|
+
|
|
13
|
+
export declare function generateQrSvgWithBuffer(options: QrOptionsWithBuffer): string
|
|
14
|
+
|
|
15
|
+
export interface QrOptions {
|
|
16
|
+
text: string
|
|
17
|
+
size?: number
|
|
18
|
+
margin?: number
|
|
19
|
+
logoPath?: string
|
|
20
|
+
logoSizeRatio?: number
|
|
21
|
+
backgroundColor?: string
|
|
22
|
+
foregroundColor?: string
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface QrOptionsWithBuffer {
|
|
26
|
+
text: string
|
|
27
|
+
size?: number
|
|
28
|
+
margin?: number
|
|
29
|
+
logoBuffer?: Buffer
|
|
30
|
+
logoSizeRatio?: number
|
|
31
|
+
backgroundColor?: string
|
|
32
|
+
foregroundColor?: string
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface QrResult {
|
|
36
|
+
svg?: string
|
|
37
|
+
png?: Buffer
|
|
38
|
+
width: number
|
|
39
|
+
height: number
|
|
40
|
+
}
|