Skip to content
This repository has been archived by the owner on Apr 15, 2024. It is now read-only.

Commit

Permalink
Doc update
Browse files Browse the repository at this point in the history
  • Loading branch information
HamAndRock committed Jan 28, 2021
1 parent a662b40 commit c9b2be7
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 27 deletions.
72 changes: 49 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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"
}
}

0 comments on commit c9b2be7

Please sign in to comment.