# Options and styles (laravel-go-qrcode)

> Pass options to qrcode.New, Generator.With, laravelqr.New, laravelqr.Response or the view functions. They apply in order, so a later option wins.

- Package: laravel-go-qrcode (Laravel for Go, alpha), go modules: `github.com/bowerbird-si/laravel-go-qrcode`
- Maintenance: active; Latest release: 0.1.0 (2026-12-04); Framework: go.laravel.com v0.2.0 or later; Go: Go 1.27 or later; Licence: MIT
- Links: [Repository](https://github.com/bowerbird-si/laravel-go-qrcode), [pkg.go.dev](https://pkg.go.dev/github.com/bowerbird-si/laravel-go-qrcode@v0.1.0), [Changelog](https://oss.bowerbird.si/go-qrcode/docs/changelog/), [Contributing](https://github.com/bowerbird-si/laravel-go-qrcode/blob/ba3241b489aeb301f0dcce65f5cea9e55f79dc24/CONTRIBUTING.md), [Security policy](https://github.com/bowerbird-si/laravel-go-qrcode/blob/ba3241b489aeb301f0dcce65f5cea9e55f79dc24/SECURITY.md)
- Based on: [Simple QrCode](https://github.com/SimpleSoftwareIO/simple-qrcode): The QR code builder this package ports: formats, styling, logos, payload helpers and Laravel integration, following version 4.2.0.; [go-qr](https://github.com/krobertson/go-qr): QR encoding.; [gozxing](https://github.com/makiuchi-d/gozxing): Scans the generated codes in the tests.
- PHP parity: full (23 covered, 27 diverged, 0 planned of 50 abilities; 74 fixtures; follows simplesoftwareio/simple-qrcode 4.2.0; verified 2026-12-04)
- Community package, not affiliated with Laravel.
- HTML version: https://oss.bowerbird.si/go-qrcode/docs/options/
- Source: https://github.com/bowerbird-si/laravel-go-qrcode/blob/ba3241b489aeb301f0dcce65f5cea9e55f79dc24/docs/options.md

Pass options to `qrcode.New`, `Generator.With`, `laravelqr.New`, `laravelqr.Response` or the view
functions. They apply in order, so a later option wins.

## Size and margin

```go
qrcode.Size(300)  // width and height in pixels, 1–4096; default 100
qrcode.Margin(2)  // quiet zone in modules on each side; default 0
```

Scanners read codes more reliably with a margin of at least four modules. PNG output needs at least one pixel per
module, so a long text at a small size returns `ErrInvalidOption`.

## Error correction

```go
qrcode.ErrorCorrection(qrcode.High)
```

| Level | Restores about | PHP |
| --- | --- | --- |
| `qrcode.Low` (default) | 7% | `'L'` |
| `qrcode.Medium` | 15% | `'M'` |
| `qrcode.Quartile` | 25% | `'Q'` |
| `qrcode.High` | 30% | `'H'` |

Use `High` when you add a logo: the logo covers part of the code.

## Colors

```go
qrcode.Foreground(color.NRGBA{R: 30, G: 64, B: 175, A: 255})
qrcode.Background(color.NRGBA{R: 255, G: 255, B: 255, A: 255})
```

Colors are `image/color` `NRGBA` values. `A` is opacity from 0 (transparent) to 255 (opaque). SVG and
PNG support transparency; EPS returns `ErrInvalidOption` for any color that isn't opaque.

## Module style

```go
qrcode.ModuleStyle(qrcode.Dot, 0.5)
```

| Style | Draws | Amount |
| --- | --- | --- |
| `qrcode.Square` (default) | Full squares | Accepted from 0 to below 1 |
| `qrcode.Dot` | A circle per module | Diameter, above 0 and below 1 |
| `qrcode.Round` | Connected groups with rounded corners | Roundness, above 0 and below 1 |

PHP's default amount is 0.5.

## Eyes

The three finder patterns in the corners are the eyes.

```go
qrcode.EyeStyle(qrcode.EyeCircle)
qrcode.EyeColor(qrcode.TopLeft, outer, inner)
```

| Shape | Draws |
| --- | --- |
| `qrcode.EyeFollowsModule` (default) | The module style |
| `qrcode.EyeSquare` | A square ring and a square center |
| `qrcode.EyeCircle` | A square ring and a round center |

`EyeColor` sets one eye: `qrcode.TopLeft`, `qrcode.TopRight` or `qrcode.BottomLeft`. The first color
is the outer ring, the second the center. Call it once per eye you want to color.

## Gradient

```go
qrcode.Gradient(
	color.NRGBA{R: 30, G: 64, B: 175, A: 255},
	color.NRGBA{R: 124, G: 58, B: 237, A: 255},
	qrcode.Diagonal,
)
```

The gradient replaces the foreground color. Eyes colored with `EyeColor` keep their own colors.

| Type | Runs |
| --- | --- |
| `qrcode.Vertical` | Top to bottom |
| `qrcode.Horizontal` | Left to right |
| `qrcode.Diagonal` | Top left to bottom right |
| `qrcode.InverseDiagonal` | Bottom left to top right |
| `qrcode.Radial` | Center to edge |

## Encoding

```go
qrcode.Encoding("UTF-8")
```

You always pass text as a Go (UTF-8) string; `Encoding` sets the character set written into the code.
The default is ISO-8859-1, like PHP. Names are case-insensitive:

Byte encodings include ISO-8859-1 through ISO-8859-11, ISO-8859-13 through ISO-8859-16, Shift-JIS
(also `SJIS` and `SHIFT_JIS`), Windows-1250, Windows-1251, Windows-1252, Windows-1256, UTF-16BE, UTF-8,
ASCII, GBK and EUC-KR. ISO-8859-12 remains accepted for numeric and alphanumeric segments, which use QR-specific alphabets.

An unknown name returns `ErrInvalidOption` when you set it. Text that the character set can't represent
returns `ErrUnencodable` when you render. For text outside Western European characters, use `UTF-8`.

## Logo

A logo is drawn in the center of PNG output.

```go
data, err := os.ReadFile("resources/logo.png")
if err != nil {
	return err
}
g, err := qrcode.New(
	qrcode.Size(400),
	qrcode.ErrorCorrection(qrcode.High),
	qrcode.LogoBytes(data, 0.2),
)
if err != nil {
	return err
}
png, err := g.PNG("https://example.com")
```

- `LogoBytes(data, fraction)` decodes PNG, JPEG or the first frame of a GIF, up to 16 MiB.
- `Logo(img, fraction)` takes an `image.Image` you already have.
- `fraction` is the logo's largest width relative to the code, typically 0.2. The logo keeps its aspect
  ratio.
- The option copies the image when you create it, so you can reuse it across generators and goroutines.
- Rendering SVG or EPS with a logo returns `ErrInvalidOption`.

Scan the result at the size you will print it: a large logo at a low error correction level can make
the code unreadable.

## Custom rendering

`Encode` returns the symbol without rendering it:

```go
m, err := g.Encode("https://example.com")
if err != nil {
	return err
}
for y := 0; y < m.Size(); y++ {
	for x := 0; x < m.Size(); x++ {
		if m.At(x, y) {
			// draw a dark module
		}
	}
}
```

`m.Version()` and `m.Level()` report the QR version and error correction level. The matrix has no quiet
zone; add your own margin.
