# (lispkit draw barcode)

Library `(lispkit draw barcode)` provides procedures for generating images of barcodes. Supported are *Code 128*, *QR Code*, *Aztec*, and *PDF417* barcodes.

*Code 128* is a high-density linear barcode defined in ISO 15417. It is used for alphanumeric or numeric-only barcodes and can encode any of the 128 ASCII characters. *GS1-128* (formerly known as *UCC/EAN-128*) is a subset of *Code 128* and is used extensively worldwide in retail, shipping and packaging industries as a product identification code.

<div align="center"><figure><img src="https://1467949168-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fna2foeoaXHYkSD3fhs0t%2Fuploads%2FGayoFXpcbSSd7FyIryy7%2Fcode128.png?alt=media&#x26;token=917fd07e-1f23-410e-8dd4-52f2ee4bad00" alt=""><figcaption></figcaption></figure></div>

*QR codes* (quick-response codes) are two-dimensional matrix barcodes, featureing black squares on a white background with fiducial markers, readable by imaging devices like cameras, and processed using Reed–Solomon error correction.

<figure><img src="https://1467949168-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fna2foeoaXHYkSD3fhs0t%2Fuploads%2F2W6v1H6QaOZM2hvVVrk3%2Fqrcode.png?alt=media&#x26;token=d982d3f0-1c76-488e-885b-bede37a57d5c" alt=""><figcaption></figcaption></figure>

*Aztec codes* are matrix codes defined by ISO 24778. Named after the resemblance of the central finder pattern to an Aztec pyramid, Aztec codes have the potential to use less space than other matrix barcodes because they do not require a surrounding blank/"quiet" zone.

<figure><img src="https://1467949168-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fna2foeoaXHYkSD3fhs0t%2Fuploads%2FhldAJXvcwUqwjApifdjz%2Faztec.png?alt=media&#x26;token=2f376fae-e7c0-426b-a342-2ec01cd13c77" alt=""><figcaption></figcaption></figure>

*PDF417* is a stacked linear barcode format used in a variety of applications such as transport, identification cards, and inventory management. It is defined in ISO 15438.

<figure><img src="https://1467949168-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fna2foeoaXHYkSD3fhs0t%2Fuploads%2FDo7rnX3datR2wefHSWVB%2Fpdf417.png?alt=media&#x26;token=d05736cf-55f8-48df-aae2-cff13b24b180" alt=""><figcaption></figcaption></figure>

**(code128-image&#x20;*****str height*****)**     <img src="https://1467949168-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fna2foeoaXHYkSD3fhs0t%2Fuploads%2Fgit-blob-d20368c588cfbb523beb2fae4f8be0f8ef011884%2Fproc.png?alt=media" alt="" data-size="line">\
\&#xNAN;**(code128-image&#x20;*****str height pad*****)**\
\&#xNAN;**(code128-image&#x20;*****str height pad scale*****)**\
\&#xNAN;**(code128-image&#x20;*****str height pad scale color*****)**\
\&#xNAN;**(code128-image&#x20;*****str height pad scale color backgr*****)**\
\&#xNAN;**(code128-image&#x20;*****str height pad scale color backgr ppi*****)**

Returns a [*Code 128*](https://en.wikipedia.org/wiki/Code_128) barcode for the given string *str* and *height* in points as a bitmap image. *pad* defines the padding around the barcode in points (default: 0.0). It is possible to scale the barcode with scaling factor *scale* (default: 1.0). *color* defines the color of the barcode (default: `#f`), *backgr* defines the background color (default: `#f`). *ppi* determines the number of pixels per inch. By default, *ppi* is set to 72.

```scheme
(define bc (code128-image "010123456789012815051231" 50 10))
(save-bitmap "barcode.png" bc 'png)
```

**(qr-code-image&#x20;*****str*****)**     <img src="https://1467949168-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fna2foeoaXHYkSD3fhs0t%2Fuploads%2Fgit-blob-d20368c588cfbb523beb2fae4f8be0f8ef011884%2Fproc.png?alt=media" alt="" data-size="line">\
\&#xNAN;**(qr-code-image&#x20;*****str corr*****)**\
\&#xNAN;**(qr-code-image&#x20;*****str corr scale*****)**\
\&#xNAN;**(qr-code-image&#x20;*****str corr scale color*****)**\
\&#xNAN;**(qr-code-image&#x20;*****str corr scale color backgr*****)**\
\&#xNAN;**(qr-code-image&#x20;*****str corr scale color backgr ppi*****)**

Returns a [*QR Code*](https://en.wikipedia.org/wiki/QR_code) matrix barcode for the given string *str* with 1 pixel matrix cells as a bitmap image. *corr* is the correction level, a symbol which can be one of: `low`, `medium`, `quartile`, and `high` (default: `medium`). It is possible to scale the QR code with scaling factor *scale* (default: 2.0). *color* defines the color of the barcode (default: `#f`), *backgr* defines the background color (default: `#f`). *ppi* determines the number of pixels per inch. By default, *ppi* is set to 72.

```scheme
(define qc (qr-code-image "http://lisppad.app" 'quartile 2.5))
(save-bitmap "qrcode.png" qc 'png)
```

**(aztec-code-image&#x20;*****str*****)**     <img src="https://1467949168-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fna2foeoaXHYkSD3fhs0t%2Fuploads%2Fgit-blob-d20368c588cfbb523beb2fae4f8be0f8ef011884%2Fproc.png?alt=media" alt="" data-size="line">\
\&#xNAN;**(aztec-code-image&#x20;*****str corr*****)**\
\&#xNAN;**(aztec-code-image&#x20;*****str corr compact?*****)**\
\&#xNAN;**(aztec-code-image&#x20;*****str corr compact? scale*****)**\
\&#xNAN;**(aztec-code-image&#x20;*****str corr compact? scale color*****)**\
\&#xNAN;**(aztec-code-image&#x20;*****str corr compact? scale color backgr*****)**\
\&#xNAN;**(aztec-code-image&#x20;*****str corr compact? scale color backgr ppi*****)**

Returns an [Aztec Code](https://en.wikipedia.org/wiki/Aztec_Code) matrix barcode for the given string *str* with 1 pixel matrix cells as a bitmap image. *corr* is the correction level (default: 23.0). If *compact?* is provided, it can be used to select between a standard and a compact representation (default: `()`). It is possible to scale the Aztec code with scaling factor *scale* (default: 1.0). *color* defines the color of the barcode (default: `#f`), *backgr* defines the background color (default: `#f`). *ppi* determines the number of pixels per inch. By default, *ppi* is set to 72.

```scheme
(define ac (aztec-code-image "help@lisppad.app" #f '() 3.0))
(save-bitmap "azteccode.png" ac 'png)
```

**(pdf417-code-image&#x20;*****str*****)**     <img src="https://1467949168-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fna2foeoaXHYkSD3fhs0t%2Fuploads%2Fgit-blob-d20368c588cfbb523beb2fae4f8be0f8ef011884%2Fproc.png?alt=media" alt="" data-size="line">\
\&#xNAN;**(pdf417-code-image&#x20;*****str config*****)**\
\&#xNAN;**(pdf417-code-image&#x20;*****str config scale*****)**\
\&#xNAN;**(pdf417-code-image&#x20;*****str config scale color*****)**\
\&#xNAN;**(pdf417-code-image&#x20;*****str config scale color backgr*****)**\
\&#xNAN;**(pdf417-code-image&#x20;*****str config scale color backgr ppi*****)**

Returns a [PDF417](https://en.wikipedia.org/wiki/PDF417) barcode for the given string *str* and barcode configuration *config* as a bitmap image. *config* is an association list supporting the following symbolic keys:

* `min-width`: Minimum width in points
* `max-width`: Maximum width in points
* `min-height`: Minimum height in points
* `max-height`: Maximum height in points
* `columns`: The number of columns (between 1 and 31)
* `rows`: The number of rows (between 1 and 91)
* `preferred-aspect-ratio`: Aspect ratio of the barcode
* `compaction-mode`: Compaction mode (between 0 and 4)
* `correction-level`: Compaction level (between 0 and 9)
* `always-specify-compaction`: Is compaction mode always required? (bool)

It is possible to scale the PDF417 barcode with scaling factor *scale* (default: 1.0). *color* defines the color of the barcode (default: `#f`), *backgr* defines the background color (default: `#f`). *ppi* determines the number of pixels per inch. By default, *ppi* is set to 72.

```scheme
(define pc (pdf417-code-image "help@lisppad.app" '() 1.5))
(save-bitmap "pdf417.png" pc 'png)
```
