ablunier/dinesh-barcode
Laravel integration for the Dinesh barcode generator. Generate barcodes as SVG, PNG, or HTML through a simple facade and configurable settings, making it easy to add scannable codes to invoices, labels, tickets, and other Laravel applications.
Install with composer require ablunier/dinesh-barcode. The service provider (Dinesh\Barcode\BarcodeServiceProvider) and the DNS1D / DNS2D facade aliases are auto-discovered on Laravel 5.5+; no manual config/app.php edits needed.
Pin to ^3.3.0 if you are on PHP 7.4 or 8.x. This release replaces curly-brace string offsets ($str{0}) with square-bracket offsets ($str[0]). Curly-brace offsets were deprecated in PHP 7.4 and removed in PHP 8.0, so any tag before v3.3.0 is a hard parse error on PHP 8 — which is every Laravel 9/10/11 app.
First use case — drop a QR code into a Blade view:
{!! DNS2D::getBarcodeHTML('https://example.com/inv/123', 'QRCODE', 4, 4) !!}
and a 1D barcode for a SKU:
<img src="data:image/png;base64,{{ DNS1D::getBarcodePNG($sku, 'C128', 2, 60) }}" alt="{{ $sku }}">
Where to look first: src/DNS1D.php and src/DNS2D.php. Each contains the big switch over symbology names (C39, C128, EAN13, UPCA, I25, MSI, POSTNET, PHARMA2T, … for 1D; QRCODE, PDF417, DATAMATRIX for 2D) plus the getBarcode* output methods. That switch is the de-facto API reference — there is no rich docs site.
Publish the config (php artisan vendor:publish) and set the store_path to storage/app/barcodes before you use any of the path-writing helpers; the default is often a package-relative path that is not writable in production.
getBarcodeHTML emits a table/div soup with inline styles — fine for a screen, bad for email and bad for PDF engines. For print (labels, invoices, dompdf/snappy) prefer getBarcodeSVG, or a high-resolution PNG written with getBarcodePNGPath.response(base64_decode(DNS1D::getBarcodePNG($code, 'C128')), 200, ['Content-Type' => 'image/png']) lets the browser cache the image and keeps HTML payloads small. Note getBarcodePNG returns base64 text, not binary — wrap it in base64_decode (or emit it as a data: URI).App\Services\BarcodeGenerator with png(), svg(), store() methods. Facades are awkward to fake in tests, and the wrapper gives you one place to swap the backend (e.g. to milon/barcode or an actively maintained fork) if this one stalls.Cache::remember() is ideal — but the cache key must include symbology, payload, width/height, colour and output format. A key of just barcode:$sku will happily serve a QR code where you asked for C128.Barcode::assertValid($type, $value) helper.Storage::disk('local') in a job, then hand file paths to your PDF/label renderer. Keeps request time flat and gives you a retry path on failures."{$type}-{$code}-{$w}x{$h}.png") so re-runs overwrite rather than accumulate, and sanitise $code — it flows into a filesystem path.Array and string offset access syntax with curly braces is no longer supported pointing into src/DNS1D.php, you are on 3.2.x or older — upgrade, don't patch vendor.getBarcodePNG() returns base64 without a data:image/png;base64, prefix. Writing the return value straight to a file with file_put_contents produces a corrupt PNG that opens as a broken image; <img src="{{ DNS1D::getBarcodePNG(...) }}"> renders nothing for the same reason.DNS1D / DNS2D only resolve unqualified in global namespace or via the alias. In namespaced classes import Dinesh\Barcode\Facades\DNS1DFacade or use \DNS1D.Storage::url() or asset() before putting them in a view; on a multi-server setup also make sure the disk is shared.strlen($output) > 0 and check the PNG magic bytes (\x89PNG) in tests instead of snapshotting pixels.switch in DNS1D.php/DNS2D.php; there is no driver/registry to hook into. Keep the package behind your own interface so that a fork-level change never leaks into call sites.ablunier/dinesh-barcode) of an older package, and v3.3.0 is a single-line compatibility patch. Keep the dependency on a current constraint and re-check after each Laravel major — a PHP-version bump is exactly the kind of release that gets missed here.How can I help you explore Laravel packages today?