# node-qrcode
> QR code/2d barcode generator.
[![Travis](https://img.shields.io/travis/soldair/node-qrcode.svg?style=flat-square)](http://travis-ci.org/soldair/node-qrcode)
[![npm](https://img.shields.io/npm/v/qrcode.svg?style=flat-square)](https://www.npmjs.com/package/qrcode)
[![npm](https://img.shields.io/npm/dt/qrcode.svg?style=flat-square)](https://www.npmjs.com/package/qrcode)
[![npm](https://img.shields.io/npm/l/qrcode.svg?style=flat-square)](https://github.com/soldair/node-qrcode/blob/master/license)
- [Highlights](#highlights)
- [Installation](#installation)
- [Usage](#usage)
- [Error correction level](#error-correction-level)
- [QR Code capacity](#qr-code-capacity)
- [Encoding Modes](#encoding-modes)
- [Binary data](#binary-data)
- [Multibyte characters](#multibyte-characters)
- [API](#api)
- [GS1 QR Codes](#gs1-qr-codes)
- [Credits](#credits)
- [License](#license)
## Highlights
- Works on server and client (and react native with svg)
- CLI utility
- Save QR code as image
- Support for Numeric, Alphanumeric, Kanji and Byte mode
- Support for mixed modes
- Support for chinese, cyrillic, greek and japanese characters
- Support for multibyte characters (like emojis :smile:)
- Auto generates optimized segments for best data compression and smallest QR Code size
- App agnostic readability, QR Codes by definition are app agnostic
## Installation
Inside your project folder do:
```shell
npm install --save qrcode
```
or, install it globally to use `qrcode` from the command line to save qrcode images or generate ones you can view in your terminal.
```shell
npm install -g qrcode
```
## Usage
### CLI
```
Usage: qrcode [options] <input string>
QR Code options:
-v, --qversion QR Code symbol version (1 - 40) [number]
-e, --error Error correction level [choices: "L", "M", "Q", "H"]
-m, --mask Mask pattern (0 - 7) [number]
Renderer options:
-t, --type Output type [choices: "png", "svg", "utf8"]
-w, --width Image width (px) [number]
-s, --scale Scale factor [number]
-q, --qzone Quiet zone size [number]
-l, --lightcolor Light RGBA hex color
-d, --darkcolor Dark RGBA hex color
--small Output smaller QR code to terminal [boolean]
Options:
-o, --output Output file
-h, --help Show help [boolean]
--version Show version number [boolean]
Examples:
qrcode "some text" Draw in terminal window
qrcode -o out.png "some text" Save as png image
qrcode -d F00 -o out.png "some text" Use red as foreground color
```
If not specified, output type is guessed from file extension.<br>
Recognized extensions are `png`, `svg` and `txt`.
### Browser
`node-qrcode` can be used in browser through module bundlers like [Browserify](https://github.com/substack/node-browserify) and [Webpack](https://github.com/webpack/webpack) or by including the precompiled bundle present in `build/` folder.
#### Module bundlers
```html
<!-- index.html -->
<html>
<body>
<canvas id="canvas"></canvas>
<script src="bundle.js"></script>
</body>
</html>
```
```javascript
// index.js -> bundle.js
var QRCode = require('qrcode')
var canvas = document.getElementById('canvas')
QRCode.toCanvas(canvas, 'sample text', function (error) {
if (error) console.error(error)
console.log('success!');
})
```
#### Precompiled bundle
```html
<canvas id="canvas"></canvas>
<script src="/build/qrcode.js"></script>
<script>
QRCode.toCanvas(document.getElementById('canvas'), 'sample text', function (error) {
if (error) console.error(error)
console.log('success!');
})
</script>
```
If you install through `npm`, precompiled files will be available in `node_modules/qrcode/build/` folder.
The precompiled bundle have support for [Internet Explorer 10+, Safari 5.1+, and all evergreen browsers](https://browserl.ist/?q=defaults%2C+IE+%3E%3D+10%2C+Safari+%3E%3D+5.1).
### NodeJS
Require the module `qrcode`
```javascript
var QRCode = require('qrcode')
QRCode.toDataURL('I am a pony!', function (err, url) {
console.log(url)
})
```
render a qrcode for the terminal
```js
var QRCode = require('qrcode')
QRCode.toString('I am a pony!',{type:'terminal'}, function (err, url) {
console.log(url)
})
```
### ES6/ES7
Promises and Async/Await can be used in place of callback function.
```javascript
import QRCode from 'qrcode'
// With promises
QRCode.toDataURL('I am a pony!')
.then(url => {
console.log(url)
})
.catch(err => {
console.error(err)
})
// With async/await
const generateQR = async text => {
try {
console.log(await QRCode.toDataURL(text))
} catch (err) {
console.error(err)
}
}
```
## Error correction level
Error correction capability allows to successfully scan a QR Code even if the symbol is dirty or damaged.
Four levels are available to choose according to the operating environment.
Higher levels offer a better error resistance but reduce the symbol's capacity.<br>
If the chances that the QR Code symbol may be corrupted are low (for example if it is showed through a monitor)
is possible to safely use a low error level such as `Low` or `Medium`.
Possible levels are shown below:
| Level | Error resistance |
|------------------|:----------------:|
| **L** (Low) | **~7%** |
| **M** (Medium) | **~15%** |
| **Q** (Quartile) | **~25%** |
| **H** (High) | **~30%** |
The percentage indicates the maximum amount of damaged surface after which the symbol becomes unreadable.
Error level can be set through `options.errorCorrectionLevel` property.<br>
If not specified, the default value is `M`.
```javascript
QRCode.toDataURL('some text', { errorCorrectionLevel: 'H' }, function (err, url) {
console.log(url)
})
```
## QR Code capacity
Capacity depends on symbol version and error correction level. Also encoding modes may influence the amount of storable data.
The QR Code versions range from version **1** to version **40**.<br>
Each version has a different number of modules (black and white dots), which define the symbol's size.
For version 1 they are `21x21`, for version 2 `25x25` e so on.
Higher is the version, more are the storable data, and of course bigger will be the QR Code symbol.
The table below shows the maximum number of storable characters in each encoding mode and for each error correction level.
| Mode | L | M | Q | H |
|--------------|------|------|------|------|
| Numeric | 7089 | 5596 | 3993 | 3057 |
| Alphanumeric | 4296 | 3391 | 2420 | 1852 |
| Byte | 2953 | 2331 | 1663 | 1273 |
| Kanji | 1817 | 1435 | 1024 | 784 |
**Note:** Maximum characters number can be different when using [Mixed modes](#mixed-modes).
QR Code version can be set through `options.version` property.<br>
If no version is specified, the more suitable value will be used. Unless a specific version is required, this option is not needed.
```javascript
QRCode.toDataURL('some text', { version: 2 }, function (err, url) {
console.log(url)
})
```
## Encoding modes
Modes can be used to encode a string in a more efficient way.<br>
A mode may be more suitable than others depending on the string content.
A list of supported modes are shown in the table below:
| Mode | Characters | Compression |
|--------------|-----------------------------------------------------------|-------------------------------------------|
| Numeric | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 | 3 characters are represented by 10 bits |
| Alphanumeric | 0–9, A–Z (upper-case only), space, $, %, *, +, -, ., /, : |
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
这是一个 4k 视频装换成1080p的完整示例,顺带生成一张封面 第一步安装 node 资源包里是 $ node -v v16.19.0 第二步 是安装 ffmpeg 解压后 放到 C:\ffmpeg 然后 设置环境变量 系统变量 path 编辑 添加上 C:\ffmpeg\bin 我用的是 Version: 5.1.1-essentials_build-www.gyan.dev 第三步 安装git 一直点击下一步 第四步 找到demo 文件夹 点击右键 选择 open git bash here 第五步 输入 node node-server/serve.js 就可以执行转换了
资源推荐
资源详情
资源评论
收起资源包目录
win10系统 64位 ffmpeg、node等技术 实现视频的转换 (796个子文件)
qrcode.cmd 322B
mime.cmd 316B
base.css 5KB
prettify.css 1KB
.editorconfig 569B
.eslintignore 31B
.eslintignore 10B
.eslintignore 10B
.eslintrc 1KB
.eslintrc 1KB
.eslintrc 603B
.eslintrc 404B
.eslintrc 291B
.eslintrc 253B
.eslintrc 224B
.eslintrc 208B
.eslintrc 180B
.eslintrc 176B
.eslintrc 173B
.eslintrc 172B
.eslintrc 164B
.eslintrc 43B
.eslintrc 43B
Git-2.42.0.2-64-bit.exe 58.43MB
parser.js.html 38KB
bitmapper.js.html 34KB
png.js.html 28KB
bitpacker.js.html 26KB
chunkstream.js.html 25KB
sync-inflate.js.html 24KB
filter-parse.js.html 23KB
filter-pack.js.html 23KB
parser-async.js.html 23KB
packer.js.html 19KB
index.html 18KB
parser-sync.js.html 15KB
format-normaliser.js.html 13KB
interlace.js.html 13KB
packer-sync.js.html 10KB
packer-async.js.html 8KB
sync-reader.js.html 8KB
crc.js.html 7KB
constants.js.html 6KB
filter-parse-async.js.html 5KB
filter-parse-sync.js.html 5KB
paeth-predictor.js.html 5KB
png-sync.js.html 4KB
lcov.info 28KB
browser.js 470KB
qs.js 68KB
yargs.js 48KB
parse.js 35KB
stringify.js 34KB
index.js 33KB
sbcs-data-generated.js 31KB
response.js 27KB
prettify.js 27KB
index.js 23KB
to-sjis.js 21KB
dbcs-codec.js 21KB
usage.js 20KB
ipaddr.js 19KB
index.js 18KB
command.js 18KB
conversions.js 17KB
tests.js 15KB
qrcode.js 15KB
index.js 15KB
application.js 14KB
validation.js 13KB
index.js 13KB
request.js 12KB
text.js 11KB
index.js 11KB
index.js 11KB
index.js 10KB
index.js 10KB
stringify.js 10KB
text.js 10KB
index.js 10KB
ipaddr.min.js 10KB
parse.js 9KB
segments.js 9KB
utf7.js 9KB
index.js 9KB
GetIntrinsic.js 9KB
extend-node.js 8KB
dbcs-data.js 8KB
index.js 8KB
parser.js 8KB
values.js 7KB
index.js 7KB
utils.js 7KB
index.js 7KB
indent-option.js 6KB
bitmapper.js 6KB
index.js 6KB
index.js 6KB
completion.js 6KB
internal.js 6KB
共 796 条
- 1
- 2
- 3
- 4
- 5
- 6
- 8
资源评论
zooKevin
- 粉丝: 21
- 资源: 13
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功