This page lists each milon/barcode call with its Go equivalent, and the places where the Go port behaves differently.
In PHP the size, colour and text settings are positional arguments of each call. In Go they are options
of a generator (barcode.New1D, barcode.New2D) or of one call (With, or the trailing options of the
laravelbarcode functions). In the table, gen is a barcode.Generator1D or Generator2D, and ctx
is a request context in a Laravel for Go application.
Linear barcodes (DNS1D)
| PHP | Go |
|---|---|
DNS1D::getBarcodeSVG($code, 'C39', 2, 30, 'black', true) | gen.SVG(code, barcode.C39) with BarWidth(2), Height(30), ForegroundCSS("black"), ShowCode(true) |
getBarcodeSVG(..., inline: true) | InlineSVG(true), or the barcode1D template function |
DNS1D::getBarcodeHTML($code, 'C39') | gen.HTML(code, barcode.C39), or barcode1DHTML in a template |
DNS1D::getBarcodePNG($code, 'C39', ..., $bgcolor) (base64) | gen.Base64(code, barcode.C39, barcode.PNGFormat); raw bytes with gen.PNG; Background(color.NRGBA{…}) for $bgcolor |
DNS1D::getBarcodeJPG($code, 'C39') (base64) | gen.Base64(code, barcode.C39, barcode.JPEGFormat); raw bytes with gen.JPEG |
DNS1D::getBarcodePNGPath($code, 'C39', ..., $filename) | laravelbarcode.StoreAs1D(ctx, filename, code, barcode.C39, barcode.PNGFormat), or Store1D without a filename; the path is Stored.Path |
DNS1D::getBarcodePNGUri($code, 'C39') | laravelbarcode.Store1D(ctx, code, barcode.C39, barcode.PNGFormat); the URI is Stored.URI |
getBarcodeJPGPath, getBarcodeJPGUri | The same functions with barcode.JPEGFormat |
DNS1D::setPadding($p) | Padding(p) |
The type string, such as 'c128' | A constant such as barcode.C128, or barcode.ParseType1D("c128") |
Matrix barcodes (DNS2D)
| PHP | Go |
|---|---|
DNS2D::getBarcodeSVG($code, 'QRCODE', 3, 3, 'black') | gen.SVG(code, qr) with ModuleSize(3, 3), ForegroundCSS("black") |
DNS2D::getBarcodeHTML($code, 'QRCODE') | gen.HTML(code, qr), or barcode2DHTML in a template |
DNS2D::getBarcodePNG($code, 'QRCODE') (base64) | gen.Base64(code, qr, barcode.PNGFormat); raw bytes with gen.PNG; barcode2DSrc gives a data URI in a template |
DNS2D::getBarcodePNGPath($code, 'DATAMATRIX', ..., $filename) | laravelbarcode.StoreAs2D(ctx, filename, code, barcode.DataMatrix(), barcode.PNGFormat), or Store2D |
DNS2D::getBarcodePNGUri($code, 'DATAMATRIX') | laravelbarcode.Store2D(ctx, code, barcode.DataMatrix(), barcode.PNGFormat); the URI is Stored.URI |
DNS2D::setPadding($p) | Padding(p) |
DNS2D::setLogo($path, $widthPercent) | LogoBytes(data, fraction) or Logo(img, fraction), with the file read by your code |
'QRCODE,H' | barcode.QR(barcode.QRErrorCorrection(barcode.QRHigh)), or barcode.ParseType2D("QRCODE,H") |
'DATAMATRIX' | barcode.DataMatrix() |
'PDF417,3,5' | barcode.PDF417(barcode.AspectRatio(3), barcode.PDF417ErrorCorrection(barcode.PDF417EC5)) |
'PDF417,,,2,0,1,report.pdf' (Macro PDF417) | barcode.PDF417(barcode.Macro(2, 0, 1, barcode.FileName("report.pdf"))) |
Laravel
| PHP | Go |
|---|---|
BarcodeServiceProvider | laravelbarcode.New(...) in the application's Packages |
The DNS1D and DNS2D facades | laravelbarcode.From1D(ctx) and From2D(ctx), or Response1D and Response2D for a route |
config('barcode.store_path'), setStorPath($path) | laravelbarcode.StoreDir(dir), plus StoreURL(base) for the public URI |
{!! DNS1D::getBarcodeHTML(...) !!} in Blade | {{ barcode1DHTML "code" "C39" }} in a Go template |
InvalidBarcodeException | barcode.ErrUnsupportedType, ErrInvalidCode or ErrInvalidOption, matched with errors.Is |
WrongCheckDigitException | *barcode.CheckDigitError (errors.As), which wraps ErrCheckDigit |
The defaults match PHP's: bar width 2, height 30, text shown in SVG and hidden in HTML, PNG and JPEG, module size 3 for SVG and PNG and 10 for HTML, black on a transparent PNG.
Output parity
- SVG and HTML of linear symbols match the PHP output byte for byte, except in the cases listed below.
- PNG and JPEG are compared as decoded images: size, colours, bar positions and scanlines. The compressed bytes and the font of the printed text are the port's own.
- QR Code, Data Matrix and PDF417 may choose a different module grid from PHP (the QR mask, the compaction modes, the symbol size). Given the same grid, SVG and HTML match PHP's byte for byte. In the tests, separate decoder paths read the Go symbols back and must return the input.
- Stored files get the same name and URI as PHP's for ASCII codes. A stored matrix PNG draws each module exactly; PHP's file variant draws one extra pixel on each module's far edges.
Differences
Each of these is deliberate. design/SPEC.md in the repository, section 9, specifies them in full.
Data encoding
- Codabar keeps start and stop letters you supply. It uses
Afor a missing letter at either end and rejects lettersAthroughDinside the data. PHP addsAat both ends, soA1234BbecomesAA1234BA. - Code 39 Full ASCII (
C39E,C39E+) and Code 93 (C93) preserve lowercase letters and encode the vertical tab (0x0B). PHP uppercases the input and rejects the vertical tab. - Code 128 control runs. In automatic
C128, a run of two or more bytes that needs the other subset (for example several control bytes while Subset B is active) uses a Code A or Code B latch. A Shift covers exactly one byte. PHP can put one Shift before a whole run, so a scanner reads different bytes:AB, the control bytes0x03 0x04 0x04andB(41 42 03 04 04 42) decodes as41 42 03 64 64 42from PHP's symbol and as the input from the port's. - Empty 2 of 5.
S25,S25+,I25andI25+need at least one digit. PHP draws a symbol from empty input. - Stricter input. Over-long
EAN2,EAN5,EAN8,EAN13,UPCAandUPCEinput is rejected (PHP cuts it); letters inPOSTNET,PLANETandIMBand punctuation inRMS4CCandKIXare rejected;PHARMAandPHARMA2Tenforce the standard's range;GS1-128input must be well formed with printable ASCII values. PHP cuts or drops such data, and never returns for some of it. - QR payload
\0. The two bytes backslash and zero are encoded and decode back. PHP rejects them.
Type strings
- The
QRCODElevel is case-insensitive; an unknown level is an error. PHP encodes a lowercase or padded level, such aslorH, as level L. - The
PDF417aspect ratio, error correction level and every Macro field are validated. The Macro file ID is a number from 0 to 899. Macro PDF417 follows the standard's control block, which standard decoders read back.
Rendering
- A negative padding is
ErrInvalidOption. PHP uses 0. - Text that does not fit in the height is
ErrInvalidOption; PHP draws digits over the bars or bars with a negative height. With the default height of 30, a retail SVG with its digits needsHeight(31)or more. - Label text is escaped and CSS colours are validated before they go into SVG or HTML. PHP inserts both as given.
- Limits. Input length, canvas size, module and font size, logo size and type strings have limits. PHP has none.
- Logos come from memory, never from a path or URL. A logo that cannot be decoded is an error (PHP ignores it), and a logo that does not fit is scaled down.
Laravel and stored files
- Configuration is code (
laravelbarcode.New), not a published config file. The store directory must exist; there is no fallback to the temporary directory. - Generators are values. Padding, logo and store settings belong to a generator or the package options, never to a shared instance that one call changes for the next.
- Default file names match PHP's slug for ASCII text. Other letters are transliterated only when
they are in Latin-1 or Latin Extended-A (
étoe,ßtoss,Øtoo,Łtol,Œtooe); letters of other scripts are dropped, so the slug ofStraße 界isstrasse. Laravel's slug helper transliterates more scripts, so those names can differ from PHP's. Give such codes a custom name withStoreAs1DorStoreAs2D. - Writes are confined and atomic. A custom name keeps only its last path segment, unsafe names are rejected, and each file is written to a temporary file and renamed into place.
- Errors are typed. The check-digit error always names both digits; PHP's message leaves out a digit that is 0 and swaps the two.