Giter VIP home page Giter VIP logo

qrcode-logo's Introduction

qrcode-logo

基于node-gd图形处理库,用于生成带logo的二维码图片。

效果

基础二维码 带logo二维码 带logo二维码1

安装

npm install qrcode-logo --save

关于node-gd

qrcode-logo依赖于node-gd, 若无法正常安装node-gd,请参考node-gd安装文档: https://www.npmjs.com/package/node-gd

示例

生成带logo的二维码

var fs = require('fs'),
    qrCodeLogo = require('qrcode-logo'),

    url = 'https://www.baidu.com/',
    qrcodeImgFilePath = '/Users/test/myworkspace/qr_logo.png',
    logoBuffer = fs.readFileSync('/Users/test/myworkspace/logo.png', {
        encoding: null
    });

qrCodeLogo(url, qrcodeImgFilePath, {
    size: 10,  // 二维码单位块大小
    logo: logoBuffer // logo数据
});

仅生成二维码图片

var fs = require('fs'),
    qrCodeLogo = require('qrcode-logo'),

    url = 'https://www.baidu.com/',
    qrcodeImgFilePath = '/Users/test/myworkspace/qr.png';

qrCodeLogo(url, qrcodeImgFilePath, function (err, img) {
    console.log(err, img); // img为生成二维码图片信息(包含高度、宽度等信息)
});

生成带logo(带圆角边框)且带底部文本的二维码图片

var fs = require('fs'),
    qrCodeLogo = require('qrcode-logo'),

    url = 'https://www.baidu.com/',
    qrcodeImgFilePath = '/Users/test/myworkspace/qr_logo.png',
    logoBuffer = fs.readFileSync('/Users/test/myworkspace/logo.png', {
        encoding: null
    });

qrCodeLogo(url, qrcodeImgFilePath, {
    size: 10,  // 二维码单位块大小
    margin: 2,
    logo: logoBuffer, // logo数据
    logoBorder: {   // border边框配置
        width: 4,
        color: 0xcccfff
    },
    bottomText: {  // 底部文本框配置
        text: 'A12',
        bgColor: 0xeeefff
    }
});

API

调用方式

qrcode(text, outpath, qrOpts, cb) 或 qrcode(text, outpath, cb)

参数

text(必填)

(String)生成二维码的文本、url。

outpath(必填)

(String)生成的二维码图片的文件路径。

cb(可选)

生成二维码图片文件回调方法: function (err, img) { // err 错误认息 // img 生成的二维码图片信息(高度、宽度、色值等) }

qrOpts.size(可选)

(Number)二维码图片中二维码每块大小,默认值为10(pixel)。(二维码版本区间为version1 ~ version40, 每个版本对应块数不同。该插件生成的二维码基本由41块组成,即整个二维码图片宽度为:41 * qrOpts.size + qrOpts.margin * 2 * qrOpts.size)

qrOpts.margin(可选)

(Number) 二维码周边的留白的块数,默认4(注意,此处不是真实的像素大小)。

qrOpts.parse_url(可选)

(Boolean)是否优化处理text为url的情况, 默认为true

qrOpts.logo(可选)

(Buffer) logo图片的buffer数据(目前仅支持png、jpeg格式图片)。 logo图片会设置额外背景色为白色(若logo为透明背景,则背景色会改为白色)

qrOpts.logoBorder.width(可选)

(Number)边框大小(pixel)。值为空时,不作边框渲染。

qrOpts.logoBorder.radius(可选)

(Number)logo圆角大小, 默认值为10(pixel)。

qrOpts.logoBorder.color(可选)

(Number)边框颜色,使用十六进制颜色值.默认值为0xffffff.

qrOpts.bottomText.height(可选)

(Number)文本框高度。默认值45。

qrOpts.bottomText.align(可选)

(String) 文本对齐方式。默认居中对齐。

qrOpts.bottomText.size(可选)

(Number)文本字体大小。默认值25。

qrOpts.bottomText.angle(可选)

(Number) 文本旋转角度,默认0(0~360)。

qrOpts.bottomText.color(可选)

(Number) 文本颜色,使用十六进制颜色值。默认值0x000000。

qrOpts.bottomText.bgColor(可选)

(Number) 文本框背景颜色,使用十六进制颜色值。默认值0xffffff。

qrOpts.bottomText.fontFilePath(可选)

(String) 文本字体文件路径。仅支持ttf字体文件。默认为楷体(gb-2312).

qrcode-logo's People

Contributors

fisherw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

qrcode-logo's Issues

可以生成流返回给前端吗?

类似这样的:

   var code = qr.image(url, { type: 'png',size:44 });
    res.setHeader('Content-type', 'image/png');  //sent qr image to client side
    code.pipe(res);

mac安装不上呢

用yarn和npm都不行


> node-gyp rebuild

gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
./util.sh: line 3: pkg-config: command not found
gyp: Call to './util.sh png16' returned exit status 0 while in binding.gyp. while trying to load binding.gyp
gyp ERR! configure error 
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (/Users/***/.nvm/versions/node/v8.12.0/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:345:16)
gyp ERR! stack     at emitTwo (events.js:126:13)
gyp ERR! stack     at ChildProcess.emit (events.js:214:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
gyp ERR! System Darwin 17.7.0
gyp ERR! command "/***.nvm/versions/node/v8.12.0/bin/node" "/Users/***/.nvm/versions/node/v8.12.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/***e/feather/node_modules/node-gd
gyp ERR! node -v v8.12.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/***_logs/2018-11-21T03_45_27_848Z-debug.log

这个需要安装python么

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.