> For the complete documentation index, see [llms.txt](https://boxlang.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://boxlang.ortusbooks.com/boxlang-framework/modularity/image-manipulation/reference/built-in-functions/imageqrcodegenerate.md).

# ImageQRCodeGenerate

Generates a QR code image from text. The result is a regular `BoxImage`, so it works with `ImageWrite`, `ImageResize`, `ImageWriteBase64` and the other image functions.

## Syntax

```boxlang
ImageQRCodeGenerate( text [, size] [, format] [, errorCorrection] [, quietZone] [, foreground] [, background] [, logo] [, logoScale] )
"text".toQRCode( [size] [, format] [, errorCorrection] [, quietZone] [, foreground] [, background] [, logo] [, logoScale] )
```

## Arguments

| Name            | Type    | Required | Default | Description                                                                                                 |
| --------------- | ------- | -------- | ------- | ----------------------------------------------------------------------------------------------------------- |
| text            | string  | Yes      | N/A     | The text to encode. Must be non-empty.                                                                      |
| size            | numeric | No       | 125     | Edge length of the square image in pixels. Clamped to 16 to 4096.                                           |
| format          | string  | No       | png     | Output format. Any format returned by `GetWriteableImageFormats()`.                                         |
| errorCorrection | string  | No       | M       | `L` (7%), `M` (15%), `Q` (25%) or `H` (30%). Always `H` when a logo is used.                                |
| quietZone       | numeric | No       | 4       | Light margin around the code in modules. Clamped to 0 to 32. The QR specification calls for 4.              |
| foreground      | string  | No       | black   | Color of the dark modules. A color name or hex code (`#RGB`, `#RRGGBB` or `#AARRGGBB`).                     |
| background      | string  | No       | white   | Color of the light modules. A color name or hex code. Use an alpha hex such as `#00ffffff` for transparent. |
| logo            | any     | No       | N/A     | An image, file path or URL drawn in the center of the code.                                                 |
| logoScale       | numeric | No       | 0.2     | Fraction of the code's edge length the logo covers. Clamped to 0.3.                                         |

## Returns

`BoxImage` - The QR code. Its format is set to `format`, so `getBlob` and `writeBase64` produce that format.

## Description

The module grid is scaled to the largest whole-pixel module size that fits `size`, then stretched to exactly `size` with nearest-neighbour sampling so the code stays sharp and scannable.

A logo hides part of the code, so error correction is forced to `H` when one is supplied. The generated code is scanned after the logo is drawn. If the logo makes it unreadable, for example a large logo on a very short text, an error is thrown instead of returning a code that will not scan. Use a smaller `logoScale`, a larger `size`, or more text.

## Examples

```boxlang
// Basic usage
qr = ImageQRCodeGenerate( "https://example.com/verify" )
ImageWrite( qr, "/path/to/qr.png" )

// Size, format and error correction
qr = ImageQRCodeGenerate( "ME:12345678", 250, "gif", "H" )

// Colors and a logo
qr = ImageQRCodeGenerate( text="https://example.com", size=400, foreground="#1a237e", background="white", logo="/logo.png" )

// Member function on a string
qr = "https://example.com".toQRCode( 250 )
```

## Example Output

Each of these was generated with `ImageQRCodeGenerate` and read back with `ImageQRCodeRead`, which returned the exact input text.

### Default

```boxlang
qr = ImageQRCodeGenerate( "https://boxlang.io", 250 )
```

![Default QR code](https://1598982152-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4ENvvb4b3Cmrr1qKj7y4%2Fuploads%2Fgit-blob-fb554cb7bb17c5785b5c0869f3807e8bdc75f7f8%2Fbx-image-qrcode-default.png?alt=media)

### Custom colors with high error correction

```boxlang
qr = ImageQRCodeGenerate( text="https://boxlang.io", size=250, errorCorrection="H", foreground="#1a237e", background="#ffeb3b" )
```

![Navy on yellow QR code](https://1598982152-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4ENvvb4b3Cmrr1qKj7y4%2Fuploads%2Fgit-blob-a8b97f9fb1c672be9172a6c94a27aefcd5a0ba19%2Fbx-image-qrcode-colors.png?alt=media)

### Light on dark

Readers need `tryHarder` (the default for `ImageQRCodeRead`) to scan a code that is lighter than its background.

```boxlang
qr = ImageQRCodeGenerate( text="https://boxlang.io", size=250, foreground="white", background="black" )
```

![White on black QR code](https://1598982152-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4ENvvb4b3Cmrr1qKj7y4%2Fuploads%2Fgit-blob-8ec45bb86b602a30ad39290ec76c87f0c5e48ee1%2Fbx-image-qrcode-inverted.png?alt=media)

### With a logo

```boxlang
qr = ImageQRCodeGenerate( text="https://example.com/with-logo", size=400, logo="/path/to/logo.png" )
```

![QR code with a logo in the center](https://1598982152-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4ENvvb4b3Cmrr1qKj7y4%2Fuploads%2Fgit-blob-1273904fe31ef16d3b1b41dd907ba2b94a74f3a0%2Fbx-image-qrcode-logo.png?alt=media)

### UTF-8 text

```boxlang
qr = ImageQRCodeGenerate( "héllo ✓ 日本語", 250 )
```

![QR code encoding UTF-8 text](https://1598982152-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4ENvvb4b3Cmrr1qKj7y4%2Fuploads%2Fgit-blob-68427e2e66a1adedd53a72f3e280259497f47475%2Fbx-image-qrcode-unicode.png?alt=media)

### No quiet zone

The QR specification calls for a 4 module margin. Without it some scanners will struggle to find the code.

```boxlang
qr = ImageQRCodeGenerate( text="https://boxlang.io", size=250, quietZone=0 )
```

![QR code with no margin](https://1598982152-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4ENvvb4b3Cmrr1qKj7y4%2Fuploads%2Fgit-blob-04152343e2a86cd56fb6e5e35a9949faf41eb0c5%2Fbx-image-qrcode-no-quiet-zone.png?alt=media)

## Related

* [ImageQRCodeRead](/boxlang-framework/modularity/image-manipulation/reference/built-in-functions/imageqrcoderead.md)
* [ImageWrite](/boxlang-framework/modularity/image-manipulation/reference/built-in-functions/imagewrite.md)
* [GetWriteableImageFormats](/boxlang-framework/modularity/image-manipulation/reference/built-in-functions/getwriteableimageformats.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://boxlang.ortusbooks.com/boxlang-framework/modularity/image-manipulation/reference/built-in-functions/imageqrcodegenerate.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
