diff --git a/README.md b/README.md index 18d0882..635b2c9 100644 --- a/README.md +++ b/README.md @@ -5,44 +5,70 @@ This library contains only 1 method and that is `generateQRWithImage` and uses l [qrcode](https://www.npmjs.com/package/qrcode) and [canvas](https://www.npmjs.com/package/canvas) to generate the resulting image. -## Quick Example +### Quick Example ```js - const imageBuffer; +import { generateQRWithImage } from '@trisbee/qr-image-nodejs'; - // for option values please visit https://www.npmjs.com/package/qrcode#qr-code-options library - const options = { - errorCorrectionLevel: 'Q', - color: { - dark: '#0CC8A8' - } - }; +const imageBuffer; +// for option values please visit https://www.npmjs.com/package/qrcode#qr-code-options library +const options = { + errorCorrectionLevel: 'Q', + color: { + dark: '#0CC8A8' + } +}; - // This will create QR with 'https://trisbee.com' encoded in it and with centered image also color will be #0CC8A8 - const resultWithImage = generateQRWithImage('https://trisbee.com', 500, 100, imageBuffer, options) - // This will create just QR code with 'https://trisbee.com' encoded in it in color #0CC8A8 - const resultWithoutImage = generateQRWithImage('https://trisbee.com', 500, 100, null, options) - // This will create classic B&W QR code with 'https://trisbee.com' encoded in it - const resultWithoutImageAndOptions = generateQRWithImage('https://trisbee.com', 500, 100, null, null) - // The buffer of outputed QR code - const imageBuffer = resultWithImage.buffer; +// This will create QR with 'https://trisbee.com' encoded in it and with centered image also color will be #0CC8A8 +const resultWithImage = generateQRWithImage('https://trisbee.com', 500, 100, imageBuffer, options) +// This will create just QR code with 'https://trisbee.com' encoded in it in color #0CC8A8 +const resultWithoutImage = generateQRWithImage('https://trisbee.com', 500, 100, null, options) +// This will create classic B&W QR code with 'https://trisbee.com' encoded in it +const resultWithoutImageAndOptions = generateQRWithImage('https://trisbee.com', 500, 100, null, null) - // The precentage of how much the inserted image area of QR code image covers - // if 'errorCorrectionLevel' is not specified theoretical maxium of how much the image can cover is 30% - // but we recommend to keep it under 20 and make sure the image doesn't touch the big rectangles in the corners - // of QR - const imageQRCoverage = resultWithImage.coverage +// The buffer of outputed QR code +const imageBuffer = resultWithImage.buffer; +const imageInBase64 = resultWithImage.buffer.toString('base64') + +// The precentage of how much the inserted image area of QR code image covers +// if 'errorCorrectionLevel' is not specified theoretical maxium of how much the image can cover is 30% +// but we recommend to keep it under 20 and make sure the image doesn't touch the big rectangles in the corners +// of QR +const imageQRCoverage = resultWithImage.coverage ``` + +### Express example +```ts +import express = require('express'); +import { generateQRWithImage } from '@trisbee/qr-image-nodejs'; + +const app = express(); +app.use(express.json()); +app.listen(3000); + +// When opening http://localhost:300/generateQR?content=trisbee.com the browser should render QR code of size 200 px +// and with margin of 100px +app.get('/generateQr', async (req, res) => { + const data = await generateQRWithImage(req.params.content, 200, 100) + + res.contentType('image/png') + res.end(data.buffer) +}) + + +``` + + ### Typings ```ts - generateQRWithImage(qrCodeContent: string, width: number, margin: number, imageBuffer?: Buffer, options?: QRCodeToBufferOptions) +generateQRWithImage(qrCodeContent: string, width: number, margin: number, imageBuffer?: Buffer, options?: QRCodeToBufferOptions) ``` ### Options diff --git a/package.json b/package.json index b06aaa2..ac59ef0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@trisbee/qr-image-nodejs", - "version": "1.0.4", + "version": "1.0.5", "types": "dist/index.d.ts", "description": "Allows you to generate image in middle of QR code", "main": "dist/index.js", @@ -13,12 +13,12 @@ }, "dependencies": { "canvas": "^2.6.1", - "qrcode": "^1.4.4", - "tslib": "^2.1.0" + "qrcode": "^1.4.4" }, "devDependencies": { "@types/node": "^14.0.27", "@types/qrcode": "^1.3.5", - "typescript": "^3.9.7" + "typescript": "^3.9.7", + "tslib": "^2.1.0" } }