# zxing-wasm
[](https://www.npmjs.com/package/zxing-wasm/v/latest) [](https://www.npmjs.com/package/zxing-wasm/v/latest) [](https://cdn.jsdelivr.net/npm/zxing-wasm@latest/) [](https://app.netlify.com/sites/zxing-wasm/deploys)
[ZXing-C++](https://github.com/zxing-cpp/zxing-cpp) WebAssembly as an ES/CJS module with types. Read or write barcodes in your browser (or other JS runtimes like node)!
Visit [this online demo](https://zxing-wasm-demo.netlify.app/) to quickly explore its basic functions. It works best on the latest chromium browsers.
## Build
```bash
git clone --recurse-submodules https://github.com/Sec-ant/zxing-wasm
cd zxing-wasm
npm i
# install cmake first:
# https://cmake.org/download/
npm run cmake
# install emscripten first:
# https://emscripten.org/docs/getting_started/downloads.html
npm run build:wasm
npm run build
```
## Install
```
npm i zxing-wasm
```
## Documentation
https://zxing-wasm.netlify.app/
## Demo
Demo page: https://zxing-wasm-demo.netlify.app/
Demo source: https://github.com/Sec-ant/zxing-wasm-demo
## Usage
This package exports 3 subpaths: `full`, `reader` and `writer`. You can choose whichever fits your needs. If you use TypeScript, you should set [`moduleResolution`](https://www.typescriptlang.org/docs/handbook/modules/theory.html#module-resolution) to [`bundler`](https://www.typescriptlang.org/docs/handbook/modules/reference.html#bundler), [`node16` or `nodenext`](https://www.typescriptlang.org/docs/handbook/modules/reference.html#node16-nodenext-1) in your `tsconfig.json` file to properly resolve the exported module.
### `zxing-wasm` or `zxing-wasm/full`
These 2 subpaths include functions to both read and write barcodes. The wasm binary size is ~1.17 MB.
```ts
import {
readBarcodesFromImageFile,
readBarcodesFromImageData,
writeBarcodeToImageFile,
} from "zxing-wasm";
```
or
```ts
import {
readBarcodesFromImageFile,
readBarcodesFromImageData,
writeBarcodeToImageFile,
} from "zxing-wasm/full";
```
### `zxing-wasm/reader`
This subpath only includes functions to read barcodes. The wasm binary size is ~930 KB.
```ts
import {
readBarcodesFromImageFile,
readBarcodesFromImageData,
} from "zxing-wasm/reader";
```
### `zxing-wasm/writer`
This subpath only includes a function to write barcodes. The wasm binary size is ~330 KB.
```ts
import { writeBarcodeToImageFile } from "zxing-wasm/writer";
```
### IIFE Scripts
Apart from ES and CJS modules, this package also ships IIFE scripts. The registered global variable is named `ZXingWASM`.
```html
```
### [`readBarcodesFromImageFile`](https://zxing-wasm.netlify.app/functions/full.readBarcodesFromImageFile.html) and [`readBarcodesFromImageData`](https://zxing-wasm.netlify.app/functions/full.readBarcodesFromImageData.html)
These 2 functions are for reading barcodes.
[`readBarcodesFromImageFile`](https://zxing-wasm.netlify.app/functions/full.readBarcodesFromImageFile.html) accepts an image [`Blob`](https://developer.mozilla.org/docs/Web/API/Blob) or an image [`File`](https://developer.mozilla.org/docs/Web/API/File) as the first input. They're encoded images, e.g. `.png` `.jpg` files.
[`readBarcodesFromImageData`](https://zxing-wasm.netlify.app/functions/full.readBarcodesFromImageData.html) accepts an [`ImageData`](https://developer.mozilla.org/docs/Web/API/ImageData) as the first input. They're raw pixels that usually acquired from [`