# Migrating from PHP (laravel-go-qrcode)

> Each simplesoftwareio/simple-qrcode call and its Go equivalent. In PHP you chain settings on the QrCode facade; in Go you pass options to qrcode.New (or…

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

Each simplesoftwareio/simple-qrcode call and its Go equivalent. In PHP you chain settings on the
`QrCode` facade; in Go you pass options to `qrcode.New` (or `laravelqr.New` for app-wide defaults) and
call a render method.

```php
QrCode::size(300)->margin(1)->errorCorrection('H')->generate('Hello');
```

```go
g, err := qrcode.New(qrcode.Size(300), qrcode.Margin(1), qrcode.ErrorCorrection(qrcode.High))
svg, err := g.SVG("Hello")
```

## Output

| PHP | Go |
| --- | --- |
| `QrCode::generate($text)` (SVG) | `g.SVG(text)` |
| `QrCode::format('png')->generate($text)` | `g.PNG(text)` |
| `QrCode::format('eps')->generate($text)` | `g.EPS(text)` |
| `QrCode::format($f)->generate($text)` | `g.Generate(text, qrcode.PNGFormat)` (or `SVGFormat`, `EPSFormat`) |
| `QrCode::generate($text, 'path/code.svg')` | `g.WriteTo(file, text, qrcode.SVGFormat)` or `os.WriteFile(path, svg, 0o644)` |
| `base64_encode(QrCode::format('png')->generate($text))` in `<img src>` | `g.DataURI(text, qrcode.PNGFormat)` |

Go renders PNG using the standard image encoder and a Go rasterizer.

## Settings

| PHP | Go |
| --- | --- |
| `size(300)` | `qrcode.Size(300)` |
| `margin(1)` | `qrcode.Margin(1)` |
| `errorCorrection('L' / 'M' / 'Q' / 'H')` | `qrcode.ErrorCorrection(qrcode.Low / Medium / Quartile / High)` |
| `encoding('UTF-8')` | `qrcode.Encoding("UTF-8")` |
| `color(255, 0, 0)` | `qrcode.Foreground(color.NRGBA{R: 255, A: 255})` |
| `color(255, 0, 0, 25)` | `qrcode.Foreground(color.NRGBA{R: 255, A: 64})`: Go opacity runs 0–255, PHP's alpha 0–100 |
| `backgroundColor(255, 255, 255)` | `qrcode.Background(color.NRGBA{R: 255, G: 255, B: 255, A: 255})` |
| `style('square' / 'dot' / 'round', 0.5)` | `qrcode.ModuleStyle(qrcode.Square / Dot / Round, 0.5)` |
| `eye('square' / 'circle')` | `qrcode.EyeStyle(qrcode.EyeSquare / EyeCircle)` |
| `eyeColor(0, r1, g1, b1, r2, g2, b2)` | `qrcode.EyeColor(qrcode.TopLeft, outer, inner)` (see below) |
| `gradient(r1, g1, b1, r2, g2, b2, 'diagonal')` | `qrcode.Gradient(from, to, qrcode.Diagonal)` |
| `merge('path/logo.png', .3)` | Read bytes with `os.ReadFile`, then `qrcode.LogoBytes(data, 0.3)` |
| `mergeString($bytes, .3)` | `qrcode.LogoBytes(data, 0.3)` |

Gradient types: `vertical`, `horizontal`, `diagonal`, `inverse_diagonal`, `radial` become
`qrcode.Vertical`, `Horizontal`, `Diagonal`, `InverseDiagonal`, `Radial`.

Eye indexes: `0`, `1`, `2` become `qrcode.TopLeft`, `qrcode.TopRight`, `qrcode.BottomLeft`.

To convert a PHP alpha, multiply by 2.55 and round: PHP 100 is Go 255 (opaque), PHP 25 is Go 64.

## Payload helpers

| PHP | Go |
| --- | --- |
| `QrCode::email($to, $subject, $body)` | `qrcode.Email{To: to, Subject: &subject, Body: &body}.Payload()` |
| `QrCode::phoneNumber($number)` | `qrcode.PhoneNumber{Number: number}.Payload()` |
| `QrCode::SMS($number, $message)` | `qrcode.SMS{Number: number, Body: &message}.Payload()` |
| `QrCode::geo($lat, $lng)` | `qrcode.Geo{Latitude: lat, Longitude: lng}.Payload()` |
| `QrCode::wiFi(['ssid' => …, 'encryption' => 'WPA', 'password' => …, 'hidden' => true])` | `qrcode.WiFi{SSID: …, Auth: qrcode.WiFiWPA, Password: &…, Hidden: &…}.Payload()` |
| `QrCode::BTC($address, $amount, [...])` | `qrcode.Bitcoin{Address: address, Amount: &amount, …}.Payload()` |

In PHP the helper returns the rendered image; in Go `Payload()` returns the text, and you render it
with any method: `g.PNG(text)`. Pass the amount as a decimal string such as `"0.001"`. See [Payloads](https://oss.bowerbird.si/go-qrcode/docs/payloads/)
for how the escaped text differs from PHP's.

## Laravel

| PHP | Go |
| --- | --- |
| The service provider, auto-discovered | `Packages: []laravel.Package{qr}` in `laravel.Options`, with `qr, err := laravelqr.New(…)` |
| `{!! QrCode::generate($url) !!}` in Blade | `{{ qrcode .URL }}` |
| `<img src="data:image/png;base64, {!! base64_encode(QrCode::format('png')->generate($url)) !!}">` | `<img src="{{ qrcodeSrc .URL }}">` |
| `response(QrCode::format('png')->generate($url))->header('Content-Type', 'image/png')` | `laravelqr.Response(r.Context(), url, qrcode.PNGFormat)` |
| `QrCode::…` in a controller or job | `laravelqr.From(ctx)` returns the app's generator |
| `$message->embedData(QrCode::format('png')->generate($url), 'QrCode.png', 'image/png')` | `Inline: map[string]mail.Attachment{"qr": mail.AttachData(png, "qr.png")}`, then `<img src="cid:qr">` |

See [Laravel for Go](https://oss.bowerbird.si/go-qrcode/docs/laravel/).

## Behaviour that changes

- Pass the outer finder color before the center color. PHP applies the first RGB triple to the outer ring despite calling that argument inner.
- Open logo files in the application and supply their contents. The same logo can be supplied as an `image.Image`. Use PNG for merged output.
- Supply opaque colors for EPS.
- Check errors from `New`, `With` and the render call. These cover unsupported encoding names, invalid payloads and options, and requests that exceed the symbol’s capacity.
- A different QR version or mask can represent the same payload.
