### Emscripten SDK Setup and Activation
Source: https://github.com/metafloor/bwip-js/wiki/Development/Compiling-FreeType
Downloads, installs, and activates the Emscripten SDK. Ensure to run `emsdk_env.sh` to set up the environment variables.
```bash
$ cd ~/emsdk
$ ./emsdk update
$ ./emsdk install latest
$ # Get a cup of coffee or two....
$ ./emsdk activate latest
$ . emsdk_env.sh
```
--------------------------------
### Command Line Interface Usage
Source: https://github.com/metafloor/bwip-js/blob/master/README.md
Basic usage and example for the bwip-js command-line tool. Install globally using 'npm install -g bwip-js'. The file-name must be of type .png or .svg.
```bash
$ npm install -g bwip-js
$ bwip-js
Usage: bwip-js symbol-name text [options...] file-name
bwip-js --bcid=symbol-name --text=text [options...] file-name
Example:
bwip-js code128 012345678 includetext textcolor=ff0000 my-code128.png
file-name must be type: .png or .svg
Try 'bwip-js --help' for more information.
Try 'bwip-js --symbols' for a list of supported barcode symbols.
```
--------------------------------
### Basic bwip-js Usage
Source: https://github.com/metafloor/bwip-js/blob/master/examples/example.html
Illustrates the basic setup for bwip-js, including placeholders for barcode type, text, options, and scale. This is a conceptual example.
```html
bwip-js // Barcode Writer in Pure JavaScript
Barcode Type:
Bar Text:
Alt Text:
Options:
Scale X,Y:
Image Rotation:
Normal Right Left Invert
Show Barcode
```
--------------------------------
### Install bwip-js Main Package
Source: https://github.com/metafloor/bwip-js/blob/master/README.md
Use this command to install the main bwip-js package. This package is cross-platform.
```bash
npm install bwip-js
```
--------------------------------
### Install bwip-js via npm
Source: https://github.com/metafloor/bwip-js/wiki/README-2.0
Install the latest npm module for bwip-js.
```bash
npm install bwip-js
```
--------------------------------
### Install Linux Build Dependencies
Source: https://github.com/metafloor/bwip-js/wiki/Development/Compiling-FreeType
Installs necessary packages like git, Java runtime, cmake, and g++ required for compiling FreeType.
```bash
$ sudo apt-get install git
$ sudo apt-get install default-jre
$ sudo apt-get install cmake
$ sudo apt-get install g++
```
--------------------------------
### Install and Use bwip-js CLI
Source: https://github.com/metafloor/bwip-js/wiki/README-2.0
Install bwip-js globally via npm and use it as a command-line tool for generating barcode images. The CLI supports specifying the barcode symbol, text, and output file.
```bash
$ npm install -g bwip-js
$ bwip-js
Usage: bwip-js symbol-name text [options...] png-file
bwip-js --bcid=symbol-name --text=text [options...] png-file
Try 'bwip-js --help' for more information.
Try 'bwip-js --symbols' for a list of supported barcode symbols.
```
```bash
$ bwip-js qrcode 123456789 ~/qrcode.png
```
--------------------------------
### Get bwip-js from GitHub
Source: https://github.com/metafloor/bwip-js/wiki/README-2.0
Download the latest code directly from the bwip-js GitHub repository.
```bash
https://github.com/metafloor/bwip-js
```
--------------------------------
### Install js-beautify
Source: https://github.com/metafloor/bwip-js/wiki/Development/Compiling-bwipjs
Install the `js-beautify` npm package, which is used to format the cross-compiled JavaScript code for better readability.
```bash
$ npm install js-beautify
```
--------------------------------
### Using BWIPP Specific Parameters
Source: https://github.com/metafloor/bwip-js/wiki/Online-Barcode-API
This example illustrates how to use BWIPP-specific parameters, including boolean flags and valued parameters that require URL-encoded values.
```APIDOC
## GET /?bcid={type}&text={encoded_text}&{bwipp_param}&{bwipp_valued_param}={encoded_value}
### Description
Generates a barcode using BWIPP-specific options, demonstrating boolean flags and valued parameters.
### Method
GET
### Endpoint
http://bwipjs-api.metafloor.com/
### Parameters
#### Query Parameters
- **bcid** (string) - Required - The type of barcode to generate.
- **text** (string) - Required - The value to encode, potentially containing BWIPP control characters (e.g., '^FNC1'). Must be URL-encoded if necessary.
- **parsefnc** (boolean) - Optional - Enables parsing of function characters in the text (BWIPP specific).
- **alttext** (string) - Optional - Specifies alternate text, requires URL-encoding (BWIPP specific).
### Request Example
```
http://bwipjs-api.metafloor.com/?bcid=code128&text=%5EFNC1011234567890&parsefnc&alttext=%2801%291234567890
```
### Response
#### Success Response (200)
- Content-Type: image/png - The generated barcode image.
#### Error Response (4XX)
- Content-Type: text/plain - An error message indicating the issue.
```
--------------------------------
### Verify Node.js Version
Source: https://github.com/metafloor/bwip-js/wiki/Development/Compiling-bwipjs
Verify that Node.js is installed and accessible in your system's PATH. This is a fundamental requirement for compiling and running bwip-js.
```bash
$ node --version
v5.11.0
```
--------------------------------
### Install Platform-Specific bwip-js Packages
Source: https://github.com/metafloor/bwip-js/blob/master/README.md
Install platform-specific packages if the main package does not work with your build stack. These are ES modules only, except for the node package.
```bash
npm install @bwip-js/node
```
```bash
npm install @bwip-js/browser
```
```bash
npm install @bwip-js/react-native
```
```bash
npm install @bwip-js/generic
```
--------------------------------
### Electron App with Node.js Package
Source: https://github.com/metafloor/bwip-js/blob/master/README.md
Basic HTML file for a single-window Electron app using the '@bwip-js/node' package to generate a QR code and display it. Ensure the node-js package is installed.
```html
Hello World!
Node.js ,
Chromium ,
Electron ,
bwip-js ,
and BWIPP .
```
--------------------------------
### Electron App Integration with bwip-js
Source: https://github.com/metafloor/bwip-js/wiki/README-2.0
Integrate bwip-js into an Electron application using the Node.js toBuffer() interface. This example shows how to render a QR code and display it in an HTML page.
```html
Hello World!
Node.js ,
Chromium ,
and Electron .
```
--------------------------------
### Basic Barcode Generation
Source: https://github.com/metafloor/bwip-js/wiki/Online-Barcode-API
This example demonstrates how to generate a basic barcode using the required 'bcid' (barcode type) and 'text' (value to encode) parameters.
```APIDOC
## GET /?bcid={type}&text={value}
### Description
Generates a barcode image of the specified type with the given text value.
### Method
GET
### Endpoint
http://bwipjs-api.metafloor.com/
### Parameters
#### Query Parameters
- **bcid** (string) - Required - The type of barcode to generate (e.g., code128).
- **text** (string) - Required - The value to encode in the barcode.
### Response
#### Success Response (200)
- Content-Type: image/png - The generated barcode image.
#### Error Response (4XX)
- Content-Type: text/plain - An error message indicating the issue.
```
--------------------------------
### Run bwip-js Tests
Source: https://github.com/metafloor/bwip-js/wiki/Development/Code-Coverage
Use this command to run existing test cases for a specific encoder. Ensure you have followed the compilation and setup instructions.
```bash
run "" ""
```
--------------------------------
### Advanced Barcode Generation with Options
Source: https://github.com/metafloor/bwip-js/wiki/Online-Barcode-API
This example shows how to use additional bwip-js and BWIPP parameters to customize the barcode appearance, such as scaling, rotation, and including text.
```APIDOC
## GET /?bcid={type}&text={value}&scale={factor}&rotate={orientation}&includetext&alttext={text}
### Description
Generates a barcode image with advanced customization options.
### Method
GET
### Endpoint
https://bwipjs-api.metafloor.com/
### Parameters
#### Query Parameters
- **bcid** (string) - Required - The type of barcode to generate (e.g., code128).
- **text** (string) - Required - The value to encode in the barcode.
- **scale** (integer) - Optional - Sets both x-axis and y-axis scaling factors (e.g., 3).
- **scaleX** (integer) - Optional - The x-axis scaling factor.
- **scaleY** (integer) - Optional - The y-axis scaling factor.
- **rotate** (string) - Optional - Allows rotating the image ('N', 'R', 'L', 'I'). Defaults to 'N'.
- **monochrome** (boolean) - Optional - Renders the image in monochrome.
- **includetext** (boolean) - Optional - Displays the human-readable text below the barcode (BWIPP specific).
- **alttext** (string) - Optional - Specifies alternate text to appear below the barcode (BWIPP specific). Value must be URL-encoded.
### Request Example
```
http://bwipjs-api.metafloor.com/?bcid=code128&text=AB1234567890&scale=3&rotate=I&includetext
```
### Response
#### Success Response (200)
- Content-Type: image/png - The generated barcode image.
#### Error Response (4XX)
- Content-Type: text/plain - An error message indicating the issue.
```
--------------------------------
### Verify Ghostscript Version
Source: https://github.com/metafloor/bwip-js/wiki/Development/Compiling-bwipjs
Verify that the Ghostscript wrapper script is working correctly by checking its version. This confirms the script is executable and points to the correct Ghostscript installation.
```bash
$ gs --version
9.07
```
--------------------------------
### Unused Variables Pattern: Another Example (Original)
Source: https://github.com/metafloor/bwip-js/wiki/Development/Version-1.0-Optimization-Notes
Another example of the unused variables pattern, showing multiple unused variables that can be eliminated.
```javascript
$astore($a($counttomark() - 1)); /*12357*/
var _6y = $k[--$j]; /*12357*/
var _6z = $k[--$j]; /*12357*/
var _70 = $k[--$j]; /*12357*/
$put($1.rowbits, $1.i, _6y); /*12358*/
```
--------------------------------
### Advanced Barcode Generation URL
Source: https://github.com/metafloor/bwip-js/wiki/Online-Barcode-API
This example demonstrates advanced options like scaling, rotation, and including text. Ensure BWIPP-specific options like 'includetext' are supported by the barcode type.
```url
http://bwipjs-api.metafloor.com/?bcid=code128&text=AB1234567890&scale=3&rotate=I&includetext
```
--------------------------------
### Command Line with Custom Font
Source: https://github.com/metafloor/bwip-js/blob/master/README.md
Example of using the '--loadfont' option with the bwip-js command-line utility to specify custom font metrics. The font path must be correct.
```bash
$ bwip-js code128 12345678 includetext textfont=CONS textxalign=center \
loadfont=CONS,250,100,../fonts/Inconsolata.otf /tmp/code128.png
```
--------------------------------
### React Usage with Canvas
Source: https://github.com/metafloor/bwip-js/blob/master/README.md
Minimal example of bwip-js in a React app using the toCanvas method. Ensure you import the correct package based on your environment.
```tsx
import bwipjs from 'bwip-js'; // If using the main package import
// or
import bwipjs from '@bwip-js/browser'; // Platform-specific package import
export default function App() {
return (