Skip to content

Commit

Permalink
Update readme and remove test file from deno release
Browse files Browse the repository at this point in the history
  • Loading branch information
samsam2310 committed Dec 12, 2021
1 parent 8b95264 commit 5e7a91e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ jobs:
path: |
dist/**/*.js
dist/**/*.ts
!dist/test/
publish_deno:
needs: build_and_test_deno
Expand Down
27 changes: 25 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ A webassembly build of C/C++ Zbar barcode scanning library.

Online Demo: https://zbar-wasm.github.io/demo

### Quick example (nodejs):
Install:
``` bash
npm i zbar.wasm
```

Quick example (nodejs):

``` javascript
const { createCanvas, loadImage } = require('canvas');
const { scanImageData } = require('zbar.wasm');
Expand All @@ -43,6 +42,30 @@ const main = async () => {
console.log(res[0].decode()); // Hello World
};

main();
```
### Quick example (deno):

```typescript
import { createCanvas, loadImage } from "https://deno.land/x/canvas/mod.ts";
import { scanImageData } from "https://deno.land/x/zbar_wasm/mod.ts"

const getImageData = async (src: string) => {
const img = await loadImage(src);
const canvas = createCanvas(img.width(), img.height());
const ctx = canvas.getContext('2d');
ctx.drawImage(img, 0, 0);
return ctx.getImageData(0, 0, img.width(), img.height());
};

const url = 'https://raw.githubusercontent.com/zbar-wasm/demo/master/node/test.png';
const main = async () => {
const img = await getImageData(url);
const res = await scanImageData(img);
console.log(res[0].typeName); // ZBAR_QRCODE
console.log(res[0].decode()); // Hello World
};

main();
```

Expand Down

0 comments on commit 5e7a91e

Please sign in to comment.