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.
QrCode::size(300)->margin(1)->errorCorrection('H')->generate('Hello');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
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.
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,Withand 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.