Laravel for Go Alpha

laravel-go-qrcode

Styled QR codes for Go and Laravel for Go.

Render QR codes as SVG, PNG or EPS. Set module and eye shapes, colors and gradients, and add logos to PNG output.

Read the docs Source on GitHub

go get github.com/bowerbird-si/laravel-go-qrcode@v0.1.0
Latest release
0.1.0, 2026-12-04
Maintenance
Active
Framework
go.laravel.com v0.2.0 or later
Go
Go 1.27 or later
Licence
MIT

PHP parity

Follows simplesoftwareio/simple-qrcode 4.2.0 (commit 916db7948ca6). Last verified .

Parity level
Full
Abilities
50
Covered
23
Diverged
27
Planned
0
PHP fixtures
74
Coverage by ability
  • generate · Covered · Core · 2 tests
    Generator::generate and Writer defaults
  • generate.file · Covered · 2 tests
    Generator::generate with filename
  • format.svg · Covered · Core · 3 tests
    Generator::format('svg')
  • format.png · Covered · Core · 3 tests
    Generator::format('png')
  • format.eps · Covered · 3 tests
    Generator::format('eps')
  • format.invalid · Covered · 2 tests
    Generator::format validation
  • size · Covered · Core · 3 tests
    Generator::size
  • margin · Covered · Core · 2 tests
    Generator::margin
  • correction · Covered · Core · 1 test
    Generator::errorCorrection
  • encoding · Covered · 1 test
    Generator::encoding
  • matrix.auto · Diverged · Core
    Writer automatic encoding policy
  • color.foreground · Covered · 2 tests
    Generator::color
  • color.background · Covered · 3 tests
    Generator::backgroundColor
  • color.create · Diverged
    Generator::createColor
  • gradient · Covered · 3 tests
    Generator::gradient
  • style · Covered · 3 tests
    Generator::style
  • eye · Covered · 3 tests
    Generator::eye
  • eye.color · Diverged
    Generator::eyeColor
  • merge.file · Diverged
    Generator::merge
  • merge.bytes · Covered · 1 test
    Generator::mergeString
  • merge.format · Diverged
    Generator PNG-only merge
  • image.decode · Covered · 1 test
    Image::__construct
  • image.width · Covered · 1 test
    Image::getWidth
  • image.height · Covered · 1 test
    Image::getHeight
  • image.get · Diverged
    Image::getImageResource
  • image.set · Diverged
    Image::setImageResource
  • image.merge.new · Covered · 1 test
    ImageMerge::__construct
  • image.merge · Diverged
    ImageMerge::merge
  • renderer.writer · Diverged
    Generator::getWriter
  • renderer.get · Diverged
    Generator::getRenderer
  • renderer.style · Diverged
    Generator::getRendererStyle
  • renderer.format · Diverged
    Generator::getFormatter
  • renderer.module · Diverged
    Generator::getModule
  • renderer.eye · Diverged
    Generator::getEye
  • renderer.fill · Diverged
    Generator::getFill
  • helper.email · Diverged
    Generator::email and Email
  • helper.geo · Diverged
    Generator::geo and Geo
  • helper.phone · Diverged
    Generator::phoneNumber and PhoneNumber
  • helper.sms · Diverged
    Generator::SMS and SMS
  • helper.wifi · Diverged
    Generator::wiFi and WiFi
  • helper.btc · Diverged
    Generator::BTC and BTC
  • helper.dispatch · Diverged
    Generator::__call and DataTypeInterface
  • laravel.provider.register · Covered · 1 test
    QrCodeServiceProvider::register and Composer discovery
  • laravel.provider.provides · Diverged
    QrCodeServiceProvider::provides
  • laravel.facade · Diverged
    QrCode facade alias and cache clear
  • laravel.html · Diverged · Core
    Generator::generate HtmlString and documented Blade use
  • laravel.image · Covered · 1 test
    Documented email embed and base64 PNG
  • encoding.shift-jis · Diverged
    Bacon Shift-JIS dispatch and aliases
  • encoding.invalid · Diverged
    Unknown and nonexistent encoding labels
  • generate.text · Covered · 2 tests
    UTF-8 input to the PHP writer
Differences from PHP (27)
Writer automatic encoding policy
The encoder uses its standard mask scoring and chooses the smallest fitting version. For example, 34 digits at level M fit version 1 in Go and use version 2 in PHP. Controlled matrices and automatic decoded payloads are tested.
Generator::createColor
Callers construct native color.NRGBA values with 0 to 255 opacity. PHP createColor returns a Bacon color with a 0 to 100 alpha scale.
Generator::eyeColor
Go takes outer and inner colors in physical order. PHP names the outer ring color inner and defaults the actual center to black when the second color is omitted.
Generator::merge
Callers read their own local file and pass bytes or an image. PHP file paths may resolve relative to the application or be read through URL wrappers.
Generator PNG-only merge
Adding a logo to a non-PNG format returns ErrInvalidOption. PHP silently omits the logo.
Image::getImageResource
Go accepts image.Image supplied by the caller in place of exposing a GD resource.
Image::setImageResource
A logo is snapshotted for immutable generator reuse. Applications can create a new option with an updated image.
ImageMerge::merge
Go fits the centered logo within the symbol and uses its exact aspect ratio. PHP rounds that ratio before calculating the output height.
Generator::getWriter
Go exposes io.Writer rendering and read-only matrices for custom consumers in place of Bacon's Writer object.
Generator::getRenderer
Go renders with the generator's format methods. Encode exposes a read-only matrix for custom rendering without a Bacon renderer object.
Generator::getRendererStyle
Go uses typed generator options and does not expose a Bacon RendererStyle object.
Generator::getFormatter
Go selects a typed format and returns the rendered bytes or sends them to a writer. It does not expose a Bacon image backend.
Generator::getModule
Go configures module geometry with a typed option and provides the raw matrix for custom consumers.
Generator::getEye
Go configures the finder shape with a typed option without returning a Bacon EyeInterface.
Generator::getFill
Go configures native colors and gradients through options without returning a Bacon Fill object.
Generator::email and Email
Go escapes mail query spaces as percent-20 and normalizes body line breaks to CRLF. PHP uses form encoding with plus for spaces.
Generator::geo and Geo
Go validates latitude and longitude and uses plain decimals even for tiny coordinates. PHP may format them using scientific notation.
Generator::phoneNumber and PhoneNumber
Go validates telephone numbers and converts spaces to hyphens as URI visual separators. PHP preserves spaces and otherwise returns the number verbatim.
Generator::SMS and SMS
Go uses an RFC 5724 body query with percent escaping. PHP appends an unescaped &body= suffix.
Generator::wiFi and WiFi
Go escapes WiFi delimiters and emits true or false for an explicit hidden setting. PHP writes raw fields and coerces boolean values to 1 or an empty string.
Generator::BTC and BTC
Go uses an exact decimal amount, percent-escapes URI parameters, and omits the question mark for an absent query.
Generator::__call and DataTypeInterface
Go exposes explicitly typed payload builders and composes their output with Generate. PHP dispatches helper method names dynamically to classes.
QrCodeServiceProvider::provides
The Go package registers a typed service and view functions up front. Laravel for Go uses explicit package installation without PHP deferred-provider metadata.
QrCode facade alias and cache clear
Applications explicitly install the Go package and resolve its immutable generator from the current application context. Composer aliases and static facade dispatch are PHP-specific.
Generator::generate HtmlString and documented Blade use
Only the inline SVG template helper returns trusted HTML. PNG and EPS remain binary response bodies without wrapping in an HTML string.
Bacon Shift-JIS dispatch and aliases
Go normalizes Shift-JIS aliases, writes ECI 20 in byte mode, and encodes valid Kanji without the pinned PHP TypeError.
Unknown and nonexistent encoding labels
An unknown encoding label is rejected when configuring the generator, including cases where numeric data could otherwise skip transcoding.

In practice

Render SVG and PNG

Reuse the generator to render the same text as SVG or a PNG data URI.

g, err := qrcode.New(qrcode.Size(200), qrcode.Margin(4))
if err != nil {
	log.Fatal(err)
}

svg, err := g.SVG("https://example.com")
if err != nil {
	log.Fatal(err)
}

src, err := g.DataURI("https://example.com", qrcode.PNGFormat)
if err != nil {
	log.Fatal(err)
}

Show a QR code in a Laravel view

Register the adapter to inline SVG with qrcode or get a PNG data URI with qrcodeSrc.

{{ qrcode .TicketURL }}
<img src="{{ qrcodeSrc .TicketURL }}" alt="Ticket QR code">

Built on

  • Simple QrCode: The QR code builder this package ports: formats, styling, logos, payload helpers and Laravel integration, following version 4.2.0.
  • go-qr: QR encoding.
  • gozxing: Scans the generated codes in the tests.

Go modules: github.com/bowerbird-si/laravel-go-qrcode · Upstream notices

Documentation