# Getting started (laravel-go-qrcode)

> Install the module, create a generator and render your first QR code as SVG, PNG or EPS.

- 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/getting-started/
- Source: https://github.com/bowerbird-si/laravel-go-qrcode/blob/ba3241b489aeb301f0dcce65f5cea9e55f79dc24/docs/getting-started.md

Install the module, create a generator and render your first QR code as SVG, PNG or EPS.

Add the module:

```shellscript
go get github.com/bowerbird-si/laravel-go-qrcode@v0.1.0
```

Create a generator, then render text in the format you need:

```go
g, err := qrcode.New(qrcode.Size(200), qrcode.Margin(4))
if err != nil {
	return err
}

svg, err := g.SVG("https://example.com")   // []byte, image/svg+xml
png, err := g.PNG("https://example.com")   // []byte, image/png
eps, err := g.EPS("https://example.com")   // []byte, application/postscript
```

`Generate(text, format)` does the same with a `qrcode.Format` value (`SVGFormat`, `PNGFormat`,
`EPSFormat`), and `format.ContentType()` gives its MIME type.

## Save to a file

```go
f, err := os.Create("ticket.svg")
if err != nil {
	return err
}
defer f.Close()
err = g.WriteTo(f, "https://example.com", qrcode.SVGFormat)
```

`WriteTo` accepts any `io.Writer`, such as an HTTP response or a buffer. For a small file,
`os.WriteFile("ticket.png", png, 0o644)` works too.

## Embed in HTML

`DataURI` returns a base64 `data:` URI for SVG or PNG, for use in an image source attribute.

```go
src, err := g.DataURI("https://example.com", qrcode.PNGFormat)
// data:image/png;base64,iVBOR…
```

## Reuse and override

A `Generator` is a value. `With` returns a copy with more options applied, and leaves the original
untouched, so you can share one configured generator:

```go
base, _ := qrcode.New(qrcode.Size(200))
large, err := base.With(qrcode.Size(600))
```

The zero value `qrcode.Generator{}` uses the defaults: 100 pixels, no margin, error correction level L,
ISO-8859-1, black on white, square modules. These match PHP.

## Errors

| Error | When |
| --- | --- |
| `qrcode.ErrInvalidOption` | An option value is out of range, or options don't fit the format (a logo with SVG, transparent colors with EPS) |
| `qrcode.ErrInvalidPayload` | The text is empty, or a payload helper got an invalid field |
| `qrcode.ErrUnencodable` | The text has characters the chosen encoding can't represent |
| `qrcode.ErrDataTooLong` | The text doesn't fit in a QR code at the chosen error correction level |

Check them with `errors.Is`.

See [Options and styles](https://oss.bowerbird.si/go-qrcode/docs/options/) to configure the generator.
